读取浏览器的POST请求内容到Java

发布于 2024-10-09 19:29:02 字数 152 浏览 0 评论 0原文

在我的网页中,有一个表单通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2024-10-16 19:29:02

这些是字符的 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文