3

In my project code, there is a requirement to encode the URL. its currently using httpclient 3.1 jar and uses its method URIUtil.encodeQuery() to do the job. but we are upgrading the jar to the newer version, org.apache.httpcomponents 4.4.1.

where I couldn't find any exact substitute for encodeQuery method. it has been discussed in the post What happened to URIUtil.encodePath from commons-httpclient-3.1?.

But still I am looking for any good substitute for encodeQuery(), can anyone has suggestion.

Thanks

Community
  • 1
  • 1

2 Answers2

1

In our project we use the URIBuilder class.

https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URIBuilder.html

The builder returns the standard java URI.

Felix Novovic
  • 575
  • 11
  • 21
0

If you have a new project I suggest to follow the other answer by using the Builder.

On my side, as my project is old and do not want to refactor too much, I just switched to another util class in the CXF project (as it's already a dependency I have).

I just replaced the code URIUtil.encodeQuery(strQuery) by URIParserUtil.escapeChars(strQuery)

The API documentation is here.

рüффп
  • 5,172
  • 34
  • 67
  • 113