4

我正在我的 Android 应用程序中制作一个 XML + 图像帖子,MultiPartEntity除了我要发布到的服务器要求我将Content-TypeHTTP 帖子设置为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
...

这可能不是发布它的正确方法,但我必须这样做,它会起作用。

4

1 回答 1

5

I found a way to do this and it's simply by adding a header to the HttpPost object.

        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);
于 2011-04-25T14:19:14.857 回答