【发布时间】:2018-12-14 16:24:11
【问题描述】:
我正在使用 RestTemplate 与一个 REST 服务进行通信,我使用
restTemplate.postForEntity(uri, request, MyResponse.class);
} catch (HttpClientErrorException e)
但是,当出现错误(4xx 或 5xx)时,REST 服务会在正文中返回 JSON 描述,但 HttpClientErrorException.getResponseBodyAsString() 返回空值。 RestTemplate(如果我尝试以字符串形式检索响应),也不返回任何内容。
发生错误时如何检索正文?
【问题讨论】:
-
你是如何创建restTemplate的?
标签: java spring resttemplate spring-rest