1

I have written a java swing app that is sending SOAP requests based on this code here

Overall it is working great, however I have just started testing it when parsing Chinese characters in the soap:BODY and this causes an error where I get a 400 response from the Web Server:

s.AddParameter("xml", "班"); 

Using wireshark i eventually tracked it down to the Content-Length value that was constructed being incorrect when parsing these Chinese characters (and i am assuming any other multibyte(?) character).

I have proven this by overriding the content length generation by simply changing the code to this:

out.println("Content-Length: " + String.valueOf(postData.length()+2));

Obviously this is not a solution as it only proved my very isolated test case of sending a single character, but i believe the issue is that the postData.length() is calculated first and then on posting the data my 班 character is then converted to \347\217\255, throwing the content-length out and causing the request to fail.

So I am asking for advice on how to resolve this issue?

Is it possible for me to encode the value first, obtain the content length and suppress the encoding on the post? I am unsure what is actually encoding it; the PrintWriter i am assuming?

Regards.

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
  • 1
    It seems that your problem is about the encoding of the message being transferred. There is a good answer about setting the character encoding here: http://stackoverflow.com/questions/33752787/how-to-set-character-encoding-in-soap-request – STaefi Apr 18 '16 at 08:17
  • Thank you. Following that article i changed to using the method described and that seemed to of fixed the issue. It has introduced some other complexities but i am working through them now. – user3689706 Apr 19 '16 at 06:57

0 Answers0