ging
ging

Reputation: 253

URL encoding issue for path param which has '/'

I have an issue while encoding an URL. My url might contain a path param which can include a slash "/". I need to send this path param to an external API. This is always encrypted+Encoded. But i have issues encoding '/'. Everything else is encoding except '/'.

Example:

https://url.com/bdvchewcbwj%2Fhbsdwhjkbq%3D

In the above example the path param without encoded is :

bdvchewcbwj/hbsdwhjkbq=

When i encode the above path param i am expecting the url as :

https://url.com/bdvchewcbwj%2Fhbsdwhjkbq%3D

but the result is :

bdvchewcbwj/hbsdwhjkb%3D

Input:

https://url.com/bdvchewcbwj/hbsdwhjkbq%3D

Output Expected:

https://url.com/bdvchewcbwj%2Fhbsdwhjkbq%3D

I am using okHttp client to create the request. Is there any library that just encodes the unencoded characters leaving already encoded characters?

Upvotes: 0

Views: 1251

Answers (1)

Yuriy Tsarkov
Yuriy Tsarkov

Reputation: 2548

How do you encode a parameter? For me

URLEncoder.encode("bdvchewcbwj/hbsdwhjkbq=","UTF-8");

works as expected and the result is

bdvchewcbwj%2Fhbsdwhjkbq%3D

Upvotes: 1

Related Questions