2

我正在开发一个应用程序,我使用它向 REST Web 服务发送获取请求 @RequestMapping(value = "myURLpattern", method = RequestMethod.GET, produces = "image/png")

我遇到了一个错误,如果有人在 URL 查询字符串中输入 # 它会从那里中断 http://myserver.com:8080/csg?x=1&y=2#4&z=32&p=1

所以我尝试通过过滤器对其进行编码,HTTPRequestWrapper以便#将其替换为%23使用URLEncoder.

我的问题是编码 URL,首先我需要阅读URL(request.getRequestURL()). 并且 getURL 在 # 之后再次无法读取字符串。 request.getRequestURL()只会返回(http://myserver.com:8080/csg?x=1&y=2)

在发送到 REST Web 服务之前,还有其他方法可以解析完整的 url 并对其进行编码吗?

4

1 回答 1

3

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

于 2013-09-06T12:44:05.217 回答