Krishna
Krishna

Reputation: 179

Parsing and encoding URL before sending to Rest webservice

I am developing an App where I am sending get request to REST web service using @RequestMapping(value = "myURLpattern", method = RequestMethod.GET, produces = "image/png")

I came across a bug if somebody enters # in the URL query String it breaks from there http://myserver.com:8080/csg?x=1&y=2#4&z=32&p=1

So I tried to encode it via filter HTTPRequestWrapper so that # will be replaced by %23 using URLEncoder.

My problem is for encoding URL, first I need to read the URL(request.getRequestURL()). and getURL again can't read string after #. request.getRequestURL() will return only (http://myserver.com:8080/csg?x=1&y=2)

Is there any other way to parse the complete url and encode it before sending to REST web service?

Upvotes: 2

Views: 5278

Answers (1)

Nikola Yovchev
Nikola Yovchev

Reputation: 10206

That is not a bug. Check this:

What is the meaning of # in URL and how can i use that?

A # in the url query string is wrong. You should encode it on client side, before sending it to your server. See this one: How to pass '#' in query string It is in asp, but you should find the java equivalent.

Something to get you started can be this one Java URL encoding of query string parameters

Upvotes: 3

Related Questions