错误代码
Response response = client.newCall(request).execute();
if (null == response) {
throw new GovException("response为空");
}
if (!response.isSuccessful()) {
throw new GovException("报错: " + response.message());
}
ResponseBody body = response.body();
if (null == body) {
throw new GovException("返回值为null");
}
log.info("返回值:{}", body.string());
return JSONObject.fromObject(body.string());
bug
java.lang.IllegalStateException: closed
原因
body().string()的时候数据流就关闭了,再次调用就是报错已经closed。
修改后
Response response = client.newCall(request).execute();
if (null == response) {
throw new GovException("response为空");
}
if (!response.isSuccessful()) {
throw new GovException("报错: " + response.message());
}
ResponseBody body = response.body();
if (null == body) {
throw new GovException("返回值为null");
}
String result = body.string();
log.info("返回值:{}", result);
return JSONObject.fromObject(result);