`HttpPost httppost = new HttpPost(uri+"/uploads.xml");
MultipartEntity mpEntity = new MultipartEntity();
FileBody cbFile = new FileBody(file);
//insertValue
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds);
httppost.setHeader("Content-Type", "application/octet-stream");
mpEntity.addPart("userfile", cbFile);
httppost.setEntity(mpEntity);
//execute
HttpResponse response = httpclient.execute(httppost);`
但是,当我从服务器上下载的文本文件,我不能打开它,发现其他消息(粗体文本)在文本文件中添加。
--RzBVXI2AHuDiIU5UHz-A1jZrpEg6a0JY Content-Disposition:form-data; NAME = “userfile的”;文件名= “test.txt的” 内容类型:应用/八位字节流 内容传送编码:二进制
CONTENT ...
--RzBVXI2AHuDiIU5UHz-A1jZrpEg6a0JY--
谢谢!
2015-01-07
DeanLin
+0
这是正确的Mutlipart格式。如果你需要帮助阅读它,你能分享服务器端代码吗?我们不知道您使用的是什么技术。 –
+0
我使用此代码将文件上传到Redmine问题的附件! –
+0
如果我上传图片。我仍然无法通过双击打开它。 然后我打开这个图像使用文本编辑,我发现Mutlipart格式的消息是在该图像文件,以便我无法打开它。 –