Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 为什么使用RestTemplate时ResponseEntity总是空的?_Spring Boot_Null_Resttemplate - Fatal编程技术网

Spring boot 为什么使用RestTemplate时ResponseEntity总是空的?

Spring boot 为什么使用RestTemplate时ResponseEntity总是空的?,spring-boot,null,resttemplate,Spring Boot,Null,Resttemplate,我想做一个postForEntity,但结果总是空的。原因何在 @Override public ResponseEntity<Void> updateContactProperty(final Long contactId, final String json) throws RestClientException { ResponseEntity<Void> crmResponse = null; try { crmResponse

我想做一个
postForEntity
,但结果总是空的。原因何在

@Override
public ResponseEntity<Void> updateContactProperty(final Long contactId, final String json) throws RestClientException {

    ResponseEntity<Void> crmResponse = null;
    try {
        crmResponse = crmRestTemplate.postForEntity(
                "https://api.hubapi.com/contacts/v1/contact/vid/400000001/profile?hapikey=myApiKey", json, Void.class);
    }  catch (HttpClientErrorException e) {
        e.printStackTrace();
    } catch (HttpStatusCodeException e) {
        e.printStackTrace();
    }catch (RestClientException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } catch (Error r) {
        r.printStackTrace();
    } catch (Throwable t) {
        t.printStackTrace();
    }

    return crmResponse;
}
@覆盖
public ResponseEntity updateContactProperty(最终长contactId,最终字符串json)引发RestClientException{
ResponseEntity crmResponse=null;
试一试{
crmResponse=crmRestTemplate.postForEntity(
"https://api.hubapi.com/contacts/v1/contact/vid/400000001/profile?hapikey=myApiKey“,json,Void.class);
}捕获(HttpClientErrorE异常){
e、 printStackTrace();
}捕获(HttpStatusCodeException){
e、 printStackTrace();
}捕获(RestClientException e){
e、 printStackTrace();
}捕获(例外e){
e、 printStackTrace();
}捕获(错误r){
r、 printStackTrace();
}捕获(可丢弃的t){
t、 printStackTrace();
}
返回crmResponse;
}
我尝试了
ResponseEntity
ResponseEntity
ResponseEntity

使用RestTemplate注册的MessageConverters:

  • ByteArrayHttpMessageConverter
  • StringHttpMessageConverter
  • ResourceHttpMessageConverter
  • SourceHttpMessageConverter
  • AllEncompassingFormHttpMessageConverter
  • Jaxb2RootElementHttpMessageConverter
  • 映射Jackson2HttpMessageConverter

  • 无法捕获异常…调用只是执行了,但什么也没有发生。

    问题是请求的API响应为
    HttpStatusCodeException
    和空正文
    HttpStatusCodeException
    是从
    RestClientException
    派生的,因为我首先捕获了
    RestClientException
    ,它已经被使用了,而且我没有将异常填充到我的
    updateContactProperty(…)的调用方
    方法,这样调用方就不会注意到返回的响应(或异常)。

    不,这似乎不同。
    对象.class
    而不是
    Void.class
    正如您在我的问题中看到的,我已经尝试了ResponseEntity、ResponseEntity、ResponseEntity。