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.

4

3 回答 3

2

“<”得到编码的原因是因为它不是合法的URI字符。它与字符编码无关。

如果服务器没有正确处理转义序列,那么它需要得到修复。

于 2013-01-29T09:36:50.763 回答
0

You can do

URLEncoder.encode(urlString).replace("%3C", "<")
于 2013-01-29T08:03:32.743 回答
0
URLEncoder.encode(url, "UTF-8").replaceAll("%3C", "<").replaceAll("%3E", ">");
于 2013-01-29T08:29:02.300 回答