Uploading file using POST request in Node.js

Looks like you’re already using request module. in this case all you need to post multipart/form-data is to use its form feature: var req = request.post(url, function (err, resp, body) { if (err) { console.log(‘Error!’); } else { console.log(‘URL: ‘ + body); } }); var form = req.form(); form.append(‘file’, ‘<FILE_DATA>’, { filename: ‘myfile.txt’, contentType: ‘text/plain’ … Read more

POST multipart/form-data with Objective-C

The process is as follows: Create dictionary with the userName, userEmail, and userPassword parameters. NSDictionary *params = @{@”userName” : @”rob”, @”userEmail” : @”[email protected]”, @”userPassword” : @”password”}; Determine the path for the image: NSString *path = [[NSBundle mainBundle] pathForResource:@”avatar” ofType:@”png”]; Create the request: NSString *boundary = [self generateBoundaryString]; // configure the request NSMutableURLRequest *request = [[NSMutableURLRequest … Read more

Sending an HTTP POST request on iOS

The following code describes a simple example using POST method.(How one can pass data by POST method) Here, I describe how one can use of POST method. 1. Set post string with actual username and password. NSString *post = [NSString stringWithFormat:@”Username=%@&Password=%@”,@”username”,@”password”]; 2. Encode the post string using NSASCIIStringEncoding and also the post string you need … Read more

Send POST request with JSON data using Volley

JsonObjectRequest actually accepts JSONObject as body. From this blog article, final String url = “some/url”; final JSONObject jsonBody = new JSONObject(“{\”type\”:\”example\”}”); new JsonObjectRequest(url, jsonBody, new Response.Listener<JSONObject>() { … }); Here is the source code and JavaDoc (@param jsonRequest): /** * Creates a new request. * @param method the HTTP method to use * @param url … Read more

ios Upload Image and Text using HTTP POST

Here’s code from my app to post an image to our web server: // Dictionary that holds post parameters. You can set your post parameters that your server accepts or programmed to accept. NSMutableDictionary* _params = [[NSMutableDictionary alloc] init]; [_params setObject:[NSString stringWithString:@”1.0″] forKey:[NSString stringWithString:@”ver”]]; [_params setObject:[NSString stringWithString:@”en”] forKey:[NSString stringWithString:@”lan”]]; [_params setObject:[NSString stringWithFormat:@”%d”, userId] forKey:[NSString stringWithString:@”userId”]]; … Read more

How can I use JQuery to post JSON data?

You’re passing an object, not a JSON string. When you pass an object, jQuery uses $.param to serialize the object into name-value pairs. If you pass the data as a string, it won’t be serialized: $.ajax({ type: ‘POST’, url: ‘/form/’, data: ‘{“name”:”jonas”}’, // or JSON.stringify ({name: ‘jonas’}), success: function(data) { alert(‘data: ‘ + data); }, … Read more

HTTP Request in Swift with POST method

In Swift 3 and later you can: let url = URL(string: “http://www.thisismylink.com/postName.php”)! var request = URLRequest(url: url) request.setValue(“application/x-www-form-urlencoded”, forHTTPHeaderField: “Content-Type”) request.httpMethod = “POST” let parameters: [String: Any] = [ “id”: 13, “name”: “Jack & Jill” ] request.httpBody = parameters.percentEncoded() let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data, let … Read more

How to POST raw whole JSON in the body of a Retrofit request?

The @Body annotation defines a single request body. interface Foo { @POST(“/jayson”) FooResponse postJson(@Body FooRequest body); } Since Retrofit uses Gson by default, the FooRequest instances will be serialized as JSON as the sole body of the request. public class FooRequest { final String foo; final String bar; FooRequest(String foo, String bar) { this.foo = … Read more