简体   繁体   English

org.springframework.web.client.HttpClientErrorException: 400 错误的 PUT 请求

[英]org.springframework.web.client.HttpClientErrorException: 400 Bad Request for PUT

I have been trying to make consume an API with the PUT verb using restTemplate.我一直在尝试使用 restTemplate 使用 PUT 动词来使用 API。 I have the following code我有以下代码

 RestTemplate restTemplate = new RestTemplate();
 HttpHeaders headers = new HttpHeaders();
 headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
 HttpEntity<String> entity = new HttpEntity<String>(jsonString,headers);
 restTemplate.put(Url+"/'"+id,entity, String.class);

My jsonString has the following content.我的jsonString有以下内容。

{ 
 "id":"asdfafaff-fsf3-4b1c-a7c4-13352252daa",
 "product":"MyProductName",
 "Organization":"my company name test",
 "Organizationid":"tert122Teq-rtq-q556trt-qtqtqt3-131rtqtqt",
 "ProductProperties":"Hc2",
 "Locations":{ 
   "results":[ 

    ]
 },
 "Status":"Gone",
 "DisabledByType":null,
 "roles":null,
 "Url":"wwww.google.com",
 "Key":"xxxxxxxxxx",
 "Secret":"xxxxxxxxxxx",
 "Hash":"yyhhytyutyutuet",
 "validity":null,
 "Type":"basic",
 "Reason":null,
 "Barcodes":{ 
  "results":[ 
     "tetetetetetete"
   ]
 },
 "RelatedBarcodes":{ 
  "results":[ 

  ]
},
 "CustomizedFields":{ 
   "results":[ 

  ]
}}

Everything seems ok but I am receiving this error一切似乎正常,但我收到此错误

HttpClientErrorException: 400 Bad Request.
` at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79)
at org.springframework.security.oauth2.client.http.OAuth2ErrorHandler.handleError(OAuth2ErrorHandler.java:172)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:730)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:688)
at org.springframework.security.oauth2.client.OAuth2RestTemplate.doExecute(OAuth2RestTemplate.java:128)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
at org.springframework.web.client.RestTemplate.put(RestTemplate.java:459)`

What could be the problem?可能是什么问题呢?

It is impossible to indicate what is the exact problem when we don't know the API you're trying to consume.当我们不知道您尝试使用的 API 时,就不可能指出确切的问题是什么。

HTTP status 400 means that the server was unable to process the request sent by you due to invalid syntax. HTTP 状态400表示由于语法无效,服务器无法处理您发送的请求。 It is very generic message and there may be countless reasons behind it.这是非常通用的信息,背后可能有无数的原因。

You have to figure it out by yourself what exactly causes this response.您必须自己弄清楚究竟是什么导致了这种反应。 You can achieve it by looking into received response's body.您可以通过查看收到的响应正文来实现它。 Since you have not declared which ResponseErrorHandler you want to use, the default one ( DefaultResponseErrorHandler ) has been applied.由于您尚未声明要使用哪个ResponseErrorHandler ,因此已应用默认值 ( DefaultResponseErrorHandler )。 Turn on the debug mode and put some breakpoints on method public void handleError(ClientHttpResponse response) .打开调试模式并在方法public void handleError(ClientHttpResponse response)上放置一些断点。 There you should be able to get more details from response on what went wrong and fix your request accordingly.在那里,您应该能够从响应中获得更多关于出错原因的详细信息,并相应地修复您的请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.springframework.web.client.HttpClientErrorException:400错误的请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request org.springframework.web.client.HttpClientErrorException$BadRequest: 400 错误请求 - org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request org.springframework.web.client.HttpClientErrorException:RestTemplate 中的 400 错误请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request in RestTemplate RestTemplate.postForObject - 错误:org.springframework.web.client.HttpClientErrorException:400错误请求 - RestTemplate.postForObject - Error: org.springframework.web.client.HttpClientErrorException: 400 Bad Request 我收到错误 org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request - I am getting the Error org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request binance - org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request binance 我收到错误消息“ org.springframework.web.client.HttpClientErrorException $ BadRequest:400错误请求” - I'm getting error “org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request” org.springframework.web.client.HttpClientErrorException:400使用HttpEntity restTemplate.exchange的错误请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request using HttpEntity restTemplate.exchange org.springframework.web.client.HttpClientErrorException 400 RestTemplate.postForEntity - org.springframework.web.client.HttpClientErrorException 400 RestTemplate.postForEntity org.springframework.web.client.HttpClientErrorException:400空 - org.springframework.web.client.HttpClientErrorException: 400 null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM