为什么使用HttpClient发送json总是返回400

2025-03-01 19:28:53
推荐回答(1个)
回答1:

发送请求的参数与后台 处理程序 的要求不匹配。

特别是用 spring mvc时,容易出现该问题。

比如

1
2
3
4
5
6

@RequestMapping("/api/ddd")
public @ResponseBody JsonResult
doDummy(@RequestParam("tid')Long id) {
.....
return result;
}

如果发送的url是
http://www.foo.com/api/ddd
没有参数,则400
发送请求
http://www.foo.com/api/ddd?id=2323
因为实际要求的参数是tid不是id,还是会出400错