我正在开发一个应用程序,我使用它向 REST Web 服务发送 get 请求
@RequestMapping(value = "myURLpattern", method = RequestMethod.GET, Produce = "image/png")
我遇到了一个错误,如果有人在 URL 查询字符串中输入 #,它就会从那里中断
http://myserver.com:8080/csg?x=1&y=2#4&z=32&p=1
所以我尝试通过过滤器HTTPRequestWrapper
对其进行编码,以便使用URLEncoder
将#
替换为%23
>.
我的问题是编码 URL,首先我需要读取 URL(request.getRequestURL())
。
并且 getURL 再次无法读取 # 之后的字符串。
request.getRequestURL()
将仅返回 (http://myserver.com:8080/csg?x=1&y=2)
是否有其他方法可以在发送到 REST Web 服务之前解析完整的 url 并对其进行编码?
最佳答案
这不是一个错误。检查一下:
What is the meaning of # in URL and how can i use that?
url 查询字符串中的 # 错误。在将其发送到服务器之前,您应该在客户端对其进行编码。看这个:How to pass '#' in query string 它是用 asp 编写的,但您应该找到等效的 java 版本。
可以让您开始使用这个 Java URL encoding of query string parameters
关于java - 在发送到 Rest Web 服务之前解析和编码 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18658020/