Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress url encoding with spring boot

I have created a GET/POST API using Spring boot which has a http url parameter say refid. Now this parameter is already encoded before invoking GET/POST request e.g. http://localhost:8080/users/TESTFNkJXiQAH%2FJBKxigBx

But, when I deploy this through Spring Boot, the encoded refid is encoded again and the refid changes. i.e. it becomes:

http://localhost:8080/users/TESTFNkJXiQAH%252FJBKxigBx

I want to suppress this 2nd encoding by Spring boot. Can anyone advise here?

like image 451
user5423592 Avatar asked Oct 30 '22 17:10

user5423592


1 Answers

Don't know if you are still having this problem or you found out why it's happening, but because I was trying to explain to someone the phenomenon, I looked if there is already a good explanation. But since you also ask and I didn't find any, here is my answer.

So you encode your refid

TESTFNkJXiQAH%2FJBKxigBx

before you send it through the url, which then you give into a browser. Now this is only the encoded refid. When you call it through a URL directly you have to encode it again, according to the HTML URL encoding standards. That’s why the double escape. Also read this. E.g. so if your refid looks like this

test%123

and you encode it you turn it into

test%25123

now if you also want to pass it through a url on the browser you'd have to encode it again.

test%2525123

But if a service A is using this service and service A encodes this refid properly then you wont have this problem. It's happening only because you are trying to call this api endpoint through the browser.

Of course I take for granted that you are doing this:

String decoded = URLDecoder.decode(refid, "UTF-8");

in your controller

like image 52
Alex P. Avatar answered Nov 15 '22 04:11

Alex P.