Java 将文件上载到服务器
我正在构建应用程序,使用POST将图像文件上传到服务器 几个小时后,它开始工作,但我有最后一个问题。 上传数据后,我的新文件有额外的标题:Java 将文件上载到服务器,java,upload,Java,Upload,我正在构建应用程序,使用POST将图像文件上传到服务器 几个小时后,它开始工作,但我有最后一个问题。 上传数据后,我的新文件有额外的标题: --cpPHHy2XlygEWv4fZndlhywQcKPxV33Qn0Z8EOf8^M Content-Disposition: form-data; name="file"^M Content-Type: image/jpeg^M Content-Transfer-Encoding: binary^M ^M 此标头不显示在oryginal文件中
--cpPHHy2XlygEWv4fZndlhywQcKPxV33Qn0Z8EOf8^M
Content-Disposition: form-data; name="file"^M
Content-Type: image/jpeg^M
Content-Transfer-Encoding: binary^M
^M
此标头不显示在oryginal文件中
我的上传代码是:
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();
您能帮我做些什么,使这些标题不会出现在新文件中吗?我刚才回答了一个问题,这个问题也有同样的问题。这是问题和答案,您能告诉我,我应该在哪里使用\r\n?