4

I'm making a XML + image post in my Android application with a MultiPartEntity and every thing is good except the server that I'm posting to requires me to set the Content-Typeof the HTTP post to application/soap+xml; charset="utf-8"

So how do I get to change it from this...

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
...

to this

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
...

This is probably not the correct way to post it but I have to, than it will work.

Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
Mats Hofman
  • 7,060
  • 6
  • 33
  • 48

1 Answers1

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);
Mats Hofman
  • 7,060
  • 6
  • 33
  • 48