0

我使用 HttpClient 和 httpost 上传我的图像文件以及一些参数。

我的代码看起来像

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);

我没有在服务器中获取参数值。我做错什么了吗。请指导我。

4

1 回答 1

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

多部分实体覆盖了完全丢弃其内容的 URL 编码实体。

您应该将参数值作为一个或多个主体部分添加到多部分实体

于 2013-08-03T12:16:24.913 回答