在从 Tomcat 7.0.50 升级到 Tomcat 8.5.15 的过程中,它停止识别我的一种方法的 POST 参数之一:我得到的不是正常响应,而是这条消息
HTTP Status [400] – [Bad Request]
Type Status Report
Message Required String parameter 'password' is not present
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Apache Tomcat/8.5.15
方法签名是:
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> login(
@RequestParam("password") String passwordHash,
@RequestParam("username") String loginName,
@RequestParam(value = "clientId", required = false) String clientId,
HttpServletRequest request,
HttpServletResponse response)
throws NoSuchAlgorithmException {//...
我已经从请求中捕获了流量,如您所见,password
POST 参数包含在 POST x-www-form-urlencoded
参数中:
POST http://<masked>/Server/user/login HTTP/1.1
Host: <masked>
Connection: keep-alive
Content-Length: 270
Origin: http://<masked>
X-Requested-With: ShockwaveFlash/26.0.0.131
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: */*
Referer: http://<masked>
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ru;q=0.6,he;q=0.4
Cookie: <masked>
noremember=true&password=C9TUq%2BYMIbeoW%2ByfoSCt9QJoOnmSGR8BqRKdOjufjE7%2FoHUDpPf3FHSvCUbZu4EBSKkJV2ryGs1Q77D7SFbBKZZ3joWcMTN6aTsgmPsOdW0Md1qcOkB4w4L3F53XZRlKUp2RaxCjoE0AIr%2B0WLomGFSrn8u8iTf2p4Z7Mo6ZKPA%3D&username=test%40example%2Ecom&clientId=1858390758%2E1481631908
奇怪的是它在 Tomcat 7 下完美运行
这有什么帮助?
最佳答案
终于找到原因了。
在我的 Tomcat 7.0.50 的旧配置中,我在 server.xml
的 Connector
中有 maxPostSize="0"
参数,并且我'已经将它复制到新的配置中,但是由于 Tomcat 版本 7.0.63 maxPostSize="0"
并不意味着无限,而是“空”,所以 maxPostSize="-1"
应该使用
The meaning of the value zero for the maxPostSize has also been changed to mean a limit of zero rather than no limit to align it with maxSavePostSize and to be more intuitive. (markt)
关于java - Tomcat 8.5 : Required String parameter '...' is not present,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44670164/