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)
{
}
}
每当我尝试执行此代码时,iam从服务器获取“400:BAD REQUEST”。在这里无法解决问题,有人能帮我纠正这个问题吗?Android中的多部分请求问题 - 投掷不良请求
你检查这http://stackoverflow.com/questions/11629013/android-error-multipartentity-request-sent-by-the-client-was-syntactically-i?rq=1 –
是。 。我查了一下。其实我也跟着一样。仍然有问题 –
这是Android的代码? MultipartEntity不是Android库的一部分。 –