I am trying to post data using multipart/form-data, but it is not working with httpPost method. I have to send data as json string from the API,but it is giving bad response from server if I remove content-type header, response says that do not ave permission to edit following data,
I have to send 2 parameters from the API using POST,
below is my code:
public String webPostMultiForm(List<NameValuePair> params) {
String postUrl = webServiceUrl;
httpPost = new HttpPost(postUrl);
try {
httpPost.setEntity(new UrlEncodedFormEntity(params));
httpPost.addHeader("Cookie",appStatus.getSharedStringValue(appStatus.AUTH_KEY));
httpPost.addHeader("Content-Type","multipart/form-data; boundary=assdsfdffafasf");
httpPost.addHeader("Content-Disposition", "form-data; name= args");
//httpPost.setHeader("Transfer-Encoding","chunked");
} catch (UnsupportedEncodingException uee) {
Log.e(TAG, uee.getMessage());
}
Log.e(TAG,"WebGetURL: " + postUrl);
try {
response = httpClient.execute(httpPost);
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e(TAG, "httpClient.execute(httpPost) Exception: " + e.getMessage());
} else {
Log.e(TAG, "httpClient.execute(httpPost) Exception: " + e.getClass().toString());
}
}
try {
strResponse = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e(TAG, e.getMessage());
} else {
Log.e(TAG, e.getClass().toString());
}
}
return strResponse;
}
Is there anything I am doing wrong, or any other approach for this.