String url = "http://x.x.x.x:xxx/jenkins/pipeline/updateDeployConfigId/{userNameEn}/{deployconfigId}";
url = url.replace("{userNameEn}", userNameEn)
.replace("{deployconfigId}", String.valueOf(id));
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.post(RequestBody.create(null, new byte[0]) )
.build();
try {
Response response = client.newCall(request).execute();
} catch (IOException e) {
throw new RuntimeException(e);
}
response.body().string()
- 报错:java.lang.IllegalStateException: closed
原因是多次调用了 response.body().string()。解决办法是将该值用变量存储起来。