1

We have upgraded our product from Apache HttpClient to OkHttpClient. But after migration, when special characters like %20(+) is passed in URL param or query param, its been sent to client as is, where it was decoded and sent to client with Apache HttpClient.

eg : http://ip:port/testURL?A%20B -> http://ip:port/testURL?A+B ( Apache HttpClient) http://ip:port/testURL?A%20B -> http://ip:port/testURL?A%20B ( OkHttpClient)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ashwini
  • 63
  • 2
  • 8
  • Does this answer your question? [Java URL encoding of query string parameters](https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters) – JosefZ Jul 30 '21 at 14:46
  • I have already encoded the special characters before dispatching the request to OkHttpClient, but still %20 is been sent as is and not encoded value. All other special characters are encoded expect %20. – Ashwini Aug 10 '21 at 07:24

1 Answers1

1

OkHttp attempts to preserve as much as possible on input URLs. If you want to convert parts to a canonical form, use HttpUrl.Builder and set each part independently, possibly using your original parsed HttpUrl as input.

Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128