在调用REST服务时,它给出HttpClientErrorException
,我能够检索状态码和错误消息,但是如何获得responseBody
?如何从Java异常获得响应身体异常
我在尝试波纹管代码,但无法调整到HttpResponse
。
catch(HttpClientErrorException e) {
// I am trying to typecast to HttpResponse, but its throwing error
HttpResponse response = (HttpResponse) e;
String msg = response.getEntity().getContent().toString();
}
我在做什么错?任何人都可以请建议?
你查找的Javadoc HttpClientErrorException?你会看到它继承了这些方法:getResponseBodyAsByteArray,getResponseBodyAsString,getResponseHeaders - 它们不适合吗? –