[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17386844#comment-17386844
 ] 

Oleg Kalnichevski commented on HTTPCLIENT-2166:
-----------------------------------------------

[~smallufo] I am not sure I understand the problem. The URI in question is 
clearly invalid. HC 4.5 makes an attempt to normalize it, while HC 5.1 does not.

If you want your application URIs to be correctly handled by the HTTP 
transport, make sure they are valid, for instance, by using {{URIBuilder}} to 
construct them.
{code:java}
System.out.println(new URIBuilder()
        .setScheme("https")
        .setHost("myProject.appspot.com")
        .setPath("proxy")
        .addParameter("url", "https://google.com/search?q=é";)
        .build());
{code}
output>
{noformat}
https://myProject.appspot.com/proxy?url=https%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3D%EF%BF%BD
{noformat}
Oleg

> httpclient5 5.1 incorrectly encode character
> --------------------------------------------
>
>                 Key: HTTPCLIENT-2166
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2166
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (classic)
>    Affects Versions: 5.1
>            Reporter: smallufo
>            Priority: Major
>         Attachments: appengine.png
>
>
> I build a proxy server on GAE which receives 'url' parameter , and retrieve 
> content .
> It works well when client uses httpClient 4.5 , but after httpClient 
> upgrading to 5.1 , I found it has problems encoding character.
> Full test code :
>  
> {code:java}
> import mu.KotlinLogging
> import org.apache.http.client.methods.HttpGet
> import org.apache.http.impl.client.HttpClientBuilder
> import kotlin.test.Test
> class ApacheHttpClientTest {
>   private val logger = KotlinLogging.logger { }
>   val url = 
> "https://myProject.appspot.com/proxy?url=https://google.com/search?q=é";
>   @Test
>   fun testV4() {
>     val httpClient = HttpClientBuilder.create().build()
>     val httpGet = HttpGet(url)
>     logger.info { "httpGet = $httpGet" }
>     logger.info {
>       "statusCode = ${httpClient.execute(httpGet).statusLine.statusCode}"
>     }
>   }
>   @Test
>   fun testV5() {
>     val httpClient = 
> org.apache.hc.client5.http.impl.classic.HttpClientBuilder.create().build()
>     val httpGet = org.apache.hc.client5.http.classic.methods.HttpGet(url)
>     logger.info { "httpGet = $httpGet" }
>     logger.info {
>       "code = ${httpClient.execute(httpGet).code}"
>     }
>   }
> }
> {code}
>  
>  
> When `testV4` runs , it correctly encode é to %C3%A9 in the URL. And GAE 
> console shows correct query string :
> {code:java}
> myapp.ProxyServlet doGet: url = https://google.com/search?q=é{code}
>  
> But when testV5 runs , it incorrectly encode é to %E9 . In GAE console it 
> shows :
>  
> {code:java}
> myapp.ProxyServlet doGet: url = https://google.com/search?q=� 
> {code}
>  
> The screen shot is below :
> !appengine.png!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to