Search code examples
javautf-8asciihtmlunit

Java+HtmlUnit — problem with cyrillic urlencode


I am trying to send some HTTP POST parameters to some web server and one of parameters contains cyrillic characters. So the problem is that if I use this code:


wc.getPage(requestSettings);

requestSettings.setHttpMethod(HttpMethod.POST);
requestSettings.setRequestParameters(new ArrayList());

requestSettings.getRequestParameters().add(new NameValuePair("username", "Друже бобер"));
wc.getPage(requestSettings);

Server will recieve the next urlencoded parameter: enter image description here And this is wrong decoded string "Друже бобер". So I think that HtmlUnit encode url in core with using ASCII not Unicode. How to disable url encoding or how to fix this bug? If I'll encode this string and set to NameValuePair so all percent characters will be encoded by HtmlUnit to.


Solution

  • I think you need to set the charset using the setCharset method.