我在我的Android应用程序中使用MultiPartEntity
创建了一个XML +图像帖子,除了我发布的服务器要求我设置HTTP的Content-Type
之外,一切都很好发布到application/soap+xml; charset="utf-8"
那么我该如何改变呢......
POST / HTTP/1.1
Host: 192.168.0.193:1234
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Content-Type: multipart/form-data; boundary=XR43mUmjvTb58T7crHhgj83C84qmZO_9k0-s
Content-Length: 28150
Connection: Keep-Alive
--XR43mUmjvTb58T7crHhgj83C84qmZO_9k0-s
...
到这个
POST / HTTP/1.1
Host: 192.168.0.193:1234
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Content-Type: application/soap+xml; charset="utf-8"
Content-Length: 28150
Connection: Keep-Alive
--XR43mUmjvTb58T7crHhgj83C84qmZO_9k0-s
...
这可能不是发布它的正确方法,但我必须这样做,而不是它会起作用。
答案 0 :(得分:5)
我找到了一种方法,只需向HttpPost
对象添加标题即可。
MultipartEntity entity = new MultipartEntity();
entity.addPart(xml);
entity.addPart(image);
httppost.addHeader("Content-Type", "application/soap+xml; charset=\"utf-8\"");
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);