今天与第三方对接,按照以往的方法写了个接口,入参是 json 串,结果报错:
"status":400,"error":"Bad Request","message":"Required String parameter 'token' is not present"。
经过排查发现对方接收的application/x-www-form-urlencoded 格式的请求,即入参是在body 中以键值对方式存在的,利用 postman 请求如下:
![](https://i-blog.csdnimg.cn/blog_migrate/38891ec9a844a2674be5231202f987bb.png)
代码为:
@FeignClient(name = "AA", url = "${AA.host}")
public interface TServApi {
/**
* 根据token获取用户信息
*/
@ResponseBody
@RequestMapping(value = "${AA.path}", method = RequestMethod.POST, headers = "Content-Type=application/x-www-form-urlencoded")
String querySingleUserbytoken(@RequestParam("token") String token);
}