0

I using HttpClient and httpost to upload my image file along with some parameters.

My code looks like

HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("xyz.com");

ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("name","Temp"));
postParameters.add(new BasicNameValuePair("id","12345"));
httpost.setEntity(new UrlEncodedFormEntity(postParameters));

MultipartEntity entity = new MultipartEntity();
File imgFile = new File("C:\test.img");            
FileBody imgFileBody = new FileBody(imgFile);
entity.addPart("multipartcontent", imgFileBody); //No i18n  
httpost.setEntity(entity);
HttpResponse httpResponse = httpclient.execute(httpost);

Am not getting the param values in server. Am i doing anything wrong. Please guide me.

vignesh
  • 1,573
  • 7
  • 33
  • 60

1 Answers1

0
httpost.setEntity(new UrlEncodedFormEntity(postParameters));
...  
httpost.setEntity(entity);

The multipart entity overrides the URL encoded one completely discarding its content.

You should add param values to the multipart entity as one or several body parts

ok2c
  • 26,450
  • 5
  • 63
  • 71