为什么restTemplate.exchange的响应返回null?

时间:2018-05-13 10:08:42

标签: spring-boot exception-handling spring-rest spring-web

我有破解代码,我的网络服务运行良好,但没有回复:

ResponseEntity<Object> reponse=null;
        try {
            reponse = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Object.class);

        } catch (HttpStatusCodeException e) {
            System.out.println("reponse="+reponse);


        }

我的问题是, 为什么

回复

为null但

restTemplate.exchange(url,HttpMethod.POST,requestEntity,Object.class)

不是空的吗?

1 个答案:

答案 0 :(得分:0)

我错误地在响应实体中搜索错误。但它可以在例外情况下使用。

} catch (HttpClientErrorException e) {
      System.out.println(e.getStatusCode());
      System.out.println(e.getResponseBodyAsString());
    }
相关问题