I want to send an HTTP Post request using 'form-data'. Here is a screenshot of the rest-client to show what do i want:
More Information related to headers:
POST /action HTTP/1.1
Host: requsrt-utl
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="email"
[email protected]
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="password"
123456
----WebKitFormBoundaryE19zNvXGzXaLvS5C
I tried using UrlEncodedFormEntity but it is setting the content-type as 'application/x-www-form-urlencoded' which is not correct.
My Android Code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlStr);
try {
UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(nameValuePairs);
httppost.setEntity(encodedFormEntity);
HttpResponse httpresponse = httpclient.execute(httppost);
return httpresponse.getEntity().getContent();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
When i am using this, web-service is not getting any parameter and hence it sending a message that 'parameters are absent'.
Please help!
This may help you
HttpPost httppost = new HttpPost(urlStr);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("userid", "12312"));
nameValuePairs.add(new BasicNameValuePair("sessionid", "234"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
how to add parameters in android http post?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With