【发布时间】:2013-05-15 11:54:53
【问题描述】:
private void CreateaMultiPartRequest() {
try{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://172.16.22.232:8080/RESTfulExample/rest/multiPartFileUpload");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
post.setHeader("Content-type", "multipart/form-data; boundary="+"~~~~~");
String Usersettings = "{\"uId\":\"atcc02\", \"bomId\":\"IC014654_12345\", \"fileName\":\"file_12345.pdf\"}";
File cfile = new File(receivedUri.getPath());
reqEntity.addPart("file", new FileBody(cfile,"application/octet"));
reqEntity.addPart("settings", new StringBody(Usersettings,"application/json",Charset.forName("UTF-8")));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
if (resEntity != null)
{
resEntity.consumeContent();
}
else{
}
}
catch(Exception e)
{
}
}
每当我尝试执行此代码时,我都会从服务器收到“400:BAD REQUEST”。无法在这里找出问题,有人可以帮助我纠正这个问题吗?
【问题讨论】:
-
是的..我检查了同样的..事实上我也遵循了同样的方法。问题仍然存在
-
此代码适用于 Android 吗? MultipartEntity 不是 Android 库的一部分。
-
你在wireshark中检查你的请求了吗?也许这会有所帮助
-
您发送的内容有误,根据 400 响应代码描述
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications。 400 通常会在消息中返回原因是什么。你应该先检查一下...
标签: android multipart multipartentity