RestTemplate GET 调用给出 422

RestTemplate GET call gives 422

我正在与第三方应用程序集成,这个问题是在与他们的 GET APIs 之一集成时出现的。 API 有一些 headers 和参数,它在 Postman 中工作得很好。但是,在 Java 中形成并使用 RestTemplate(交换方法)执行的相同请求会给出 422 无法解析的实体。我可能哪里出错了,可以做些什么来解决这个问题?

这实际上取决于服务器端为什么使用该 HTTP 代码进行响应。

来自 Mozilla 网站的 422 Unprocessable Entitycode 的定义:

The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.

这意味着,数据是正确的,服务器理解它,但它无法处理请求。

我建议您在 RestTemplate 中尝试使用在 Postman 上成功测试的相同精确值。

Postman 上的屏幕截图以及您在 headers 和请求参数上的一些代码快照将有助于进一步调试。 确保您没有将 @PathVariable 与 @RequestParam 弄错。