读取浏览器的POST请求内容到Java
在我的网页中,有一个表单通过 POST 请求数据发送到我的网络服务器。在我的服务器(Java)中,我正在读取请求的内容,但有些字符没有被很好地读取。例如,“=”变成“%3D”,“:”变成“%3A”,“”变成“+”。如何让我的网络服务器读取文本框中写入的这些字符?
谢谢,托默
in my web page, there is a form that sends via POST request data to my web server. In my server (Java) i'm reading the request's content, but some characters are not being read well. For example, "=" turns into "%3D", ":" turns into "%3A" and " " turns into "+". How can I make my web server read these characters as they were written in the text box?
Thanks, Tomer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些是字符的 URL 编码版本。
如果您处于 Servlet 上下文中,并且只需执行 request.getParameter(),您应该会自动获取解码的(正常)版本。
如果由于某种原因您没有得到这些,您可以使用 java.net.URLDecoder.decode(input, "UTF-8"); 手动解码,但您可能想做一些根本原因分析以了解为什么您首先会获得编码的内容。也许您的网络表单正在执行双重编码?
Those are the URL encoded versions of the characters.
If you are in a Servlet context and you simply do request.getParameter() you should automatically get the decoded (normal) versions.
If for some reason you aren't getting those, you can use
java.net.URLDecoder.decode(input, "UTF-8");
to decode manually, but you might wanna do some root cause analysis to see why you are getting encoded stuff in the first place. Maybe your web form is doing double encoding?