-1

I have an HttpPost that's been working well for a couple of years but I just discovered that it's failing to deliver certain characters (I can see that the params look right on the client right before they head off to the server and I can see that they arrive as little triangles on the server... also, when I make the request from a web browser everything works correctly, so, it looks like the request is not being made with the correct encoding).

Here's my code:

HttpClient client = new HttpClient();
filePost = new PostMethod(URL_PATH);
filePost.setRequestBody(nvpArray);
responseCode = client.executeMethod(filePost);

I'm hoping there's some relatively straight forward way to convert this request to handle UTF-8.

Alternatively a non straight forward way would suffice as well :)

Charles
  • 50,943
  • 13
  • 104
  • 142
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • no advice or assistance but just a down-vote... what's wrong with this question? I'm explaining exactly where I'm stuck and showing what I'm doing and asking for how to solve a very specific programming problem! Basically meeting all the SO criteria. If you're going to down-vote at least have the decency to say why! – Yevgeny Simkin May 01 '13 at 01:46

1 Answers1

0

So, after hunting around for a while I found this example and the trick turns out to be that one needs to extend PostMethod and create a small class that overrides getRequestCharSet() and returns "UTF-8" instead. In the example they are also setting content type like this:

setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=UTF-8");

I'm haven't experimented doing one but not the other, I just added both pieces to my code and it now works perfectly.

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236