如何解决Servlet request.getParameter() 在 PUT 中返回 null 但在 POST 中不返回
我正在发送一个 PUT
请求,其中 Content-Type
标头为 application/x-www-form-urlencoded
。
请求到达服务器,但问题是我无法从 Servlet 访问参数,
@Override
protected void doPut(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {
System.out.println("NAME: " + req.getParameter("name"));
System.out.println("PHONE: " + req.getParameter("phone"));
System.out.println("CT: " + req.getContentType());
}
下面是服务器的输出日志,
NAME: null
PHONE: null
CT: application/x-www-form-urlencoded
如您所见,两个参数都是 null
。但是当在 doPost(...)
中完成同样的事情时,它会起作用。
- 为什么
request.getParameter()
在PUT
中不起作用? - 如何获取
doPut()
中的参数值?
感谢任何帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。