首页 > 解决方案 > 为什么restTemplate.exchange的响应返回null?

问题描述

我有打击代码,我的网络服务运行良好,但不返回响应:

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

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


        }

我的问题是,为什么

回复

为空但

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

不为空?

标签: spring-bootexception-handlingspring-restspring-web

解决方案


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

} catch (HttpClientErrorException e) {
      System.out.println(e.getStatusCode());
      System.out.println(e.getResponseBodyAsString());
    }

推荐阅读