Karl-Johan Karlberg created HTTPCLIENT-2266:
-----------------------------------------------
Summary: UTF-8 chars unsupported in query params
Key: HTTPCLIENT-2266
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2266
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (classic)
Affects Versions: 5.2.1
Reporter: Karl-Johan Karlberg
Trying to upgrade from HttpClient 4.5.13 to HttpClient 5.2.1 we have ONE test
failing in a scary way.
The test spins up a httpserver and we use httpclient to do a simple query with
"scary Swedish chars in the query".
Here is the call that works with httpclient 4.5.x and fails with httpclient
5.2.1
{code:java}
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
URI uri = new
URI("http://localhost:4711/v1/discovery/services?serviceName=Fräs");
String s = client.execute(new HttpGet(uri), new
HttpClientResponseHandler<String>() {
@Override
public String handleResponse(ClassicHttpResponse response) throws
HttpException, IOException {
return EntityUtils.toString(response.getEntity(), "UTF-8");
}
});
System.out.println(s);
} catch (IOException e) {
throw new RuntimeException(e);
} {code}
This code results in printout of (and of cause http status 400):
{code:java}
<h1>Bad Message 400</h1><pre>reason: Bad Request</pre> {code}
HttpClient 4.5 prints "whatever the server responded and whatever statuscode".
If you give a dummy non existent path a 404 is retuned. But as soon as we
switch back to 5.2.1 it responds 400 (without exception and the evil text
"reason: Bad Request")
Debugging though the inner workings of httpclient renders nothing out of the
ordinary and if we URLEncode the "nasty" chars it works.
I.e. it works when request uri is done like:
{code:java}
URI uri = new URI("http://localhost:9112/v1/discovery/services?"+
URLEncoder.encode("Fräs", "UTF-8"));{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]