RestTemplate的GET调用返回422。

huangapple go评论65阅读模式
英文:

RestTemplate GET call gives 422

问题

我正在与第三方应用集成的过程中,这个问题出现在与他们的一个GET API集成时。该API具有一些标头和参数,在Postman中运行正常。但是,当在Java中形成相同的请求并使用RestTemplate(exchange方法)执行时,会出现422无法解析的实体错误。我可能出了什么问题,应该怎么做才能解决这个问题?

英文:

I am in the process of integrating with a third party app and this issue comes while integrating with one of their GET APIs. The API has some headers and params and it's working perfectly fine in Postman. However, the same request when formed in Java and executed with RestTemplate (exchange method) gives 422 unparsable entity. Where could I be going wrong and what could be done to fix this issue?

答案1

得分: 1

根据服务器端的情况,它为什么以HTTP代码回应取决于实际情况。

来自Mozilla网站关于422不可处理实体代码的定义:
> 超文本传输协议(HTTP)422不可处理实体响应状态代码表示服务器理解请求实体的内容类型,请求实体的语法正确,但无法处理其中包含的指令。

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

我建议您尝试使用RestTemplate,使用在Postman上成功测试过的完全相同的值。

在Postman上的截图和您的代码中关于标头和请求参数的一些快照将有助于进一步调试。
确保不要混淆@PathVariable和@RequestParam。

英文:

It really depends on the server end why it responds with that HTTP code.

Definition of 422 Unprocessable Entitycode from Mozilla website:
>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.

which means, the data is correct, and server understood it but it cannot process the request.

I suggested you try in RestTemplate using the same exact values tested successfully on Postman.

A screenshot on Postman and your some snapshot of your code on the headers and request params will help to debug further.
Make sure you don't mistake @PathVariable with @RequestParam.

huangapple
  • 本文由 发表于 2020年8月1日 11:12:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63201380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定