我正在构建使用POST将图像文件上传到服务器的应用程序。
经过几个小时它开始工作,但我有上一期。 上传数据后,我的新文件有额外的标题:
--cpPHHy2XlygEWv4fZndlhywQcKPxV33Qn0Z8EOf8^M
Content-Disposition: form-data; name="file"^M
Content-Type: image/jpeg^M
Content-Transfer-Encoding: binary^M
^M
此标题不会出现在原始文件中。
我的上传代码是:
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
String urlParam = "http://www.modesa.pl/adminPanel/ajax-tab.php?id_product="+productId+"&id_category=0&token=c4c533d2825f8791a07265d812d62d90&tab=AdminProducts&action=addImage&ajax=1&qqfile=IMG_0599.jpg";
HttpPost httppost = new HttpPost(urlParam);
File file = new File(filename);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
mpEntity.addPart("IMG_0599", cbFile);
Header[] headers2 = {
new BasicHeader("Cookie", cookieNew),
new BasicHeader("Content-Type", "multipart/form-data")
};
httppost.setEntity(mpEntity);
httppost.setHeaders(headers2);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse responseX = httpclient.execute(httppost);
HttpEntity resEntity = responseX.getEntity();
System.out.println(responseX.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
你能帮助我,做什么,这些标题不会出现在新文件中?