0

I have a rest api and when I enter a URL in the browser, part of the URL looks like this:

...where+%7B%0D%0A%3Fs+<http%3A%2F%2F...

which actually stands for

...where { ?s <http://...

Now, when I have to call the same URl through my JAVA code, I know of URLEncoder using which I am encoding the URL. When I use "UTF-8" format, the "<" in the URL is also encoded as %3C.

Is there any way of encoding such that the "<" and ">" are retained while other parts of the URL such as spaces and others are encoded properly.

2
  • 2
    I suspect that it doesn't really matter if the "<" is encoded as %3C or is sent literally. Commented Jan 29, 2013 at 8:07
  • Yes, though I have given an answer, I also feel the same. Commented Jan 29, 2013 at 8:37

3 Answers 3

2

The reason "<" get's encoded is because it's not a legal URI character. It has nothing to do with the character encoding.

If the server doesn't treat the escape sequence correctly then it needs to get fixed.

Sign up to request clarification or add additional context in comments.

1 Comment

These characters are supposed to be encoded and not considered url safe characters: en.wikipedia.org/wiki/Percent-encoding. Any urlencoder implementation that doesn't encode these is broken. Browsers tend to be somewhat forgiving with encoding what you enter in the url bar and mostly it doesn't actually break stuff.
0

You can do

URLEncoder.encode(urlString).replace("%3C", "<")

Comments

0
URLEncoder.encode(url, "UTF-8").replaceAll("%3C", "<").replaceAll("%3E", ">");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.