[ https://issues.apache.org/jira/browse/HTTPCLIENT-2266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17704041#comment-17704041 ]
Michael Osipov edited comment on HTTPCLIENT-2266 at 3/23/23 10:01 AM: ---------------------------------------------------------------------- The input is invalid because the URI you have provided is invalid. Shit in, shit out. HttpClient expects valid input, otherwise the behavior is undefined. Regarding URLEncoder: NEVER EVER use this class, this class is fraud. It does not URL encode, it does form encoding. We have a fantatisic URI builder, it is to construct your URIs. was (Author: michael-o): The input is unvalid because the URI you have provided is invalid. Shit in, shit out. HttpClient expects valid input, otherwise the behavior is undefined. Regarding URLEncoder: NEVER EVER use this class, this class is fraud. It does not URL encode, it does form encoding. We have a fantatisic URI builder, it is to construct your URIs. > 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 > Priority: Major > > 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: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org