我使用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);
未在服务器中获取参数值。我做错什么了吗。请引导我。
httpost.setEntity(new UrlEncodedFormEntity(postParameters));
...
httpost.setEntity(entity);
多部分实体覆盖URL编码的实体,完全丢弃其内容。
您应该将param值作为一个或多个身体部位添加到多部分实体