gpt4 book ai didi

apache - org.apache.http.ConnectionClosedException : Premature end of chunk coded message body: closing chunk expected

转载 作者:可可西里 更新时间:2023-11-01 15:18:58 42 4
gpt4 key购买 nike

我正在试用 RestAssured 并编写了以下语句 -

String URL = "http://XXXXXXXX";
Response result = given().
header("Authorization","Basic xxxx").
contentType("application/json").
when().
get(url);
JsonPath jp = new JsonPath(result.asString());

在最后一条语句中,我收到以下异常:

org.apache.http.ConnectionClosedException: block 编码消息正文过早结束:预期关闭 block

我的回复中返回的 header 是:

内容类型 → application/json; qs=1
日期 → 2015 年 11 月 10 日星期二 02:58:47 GMT
传输编码 → 分块

任何人都可以指导我解决此异常并指出我是否遗漏任何内容或任何不正确的实现。

最佳答案

我有一个与 无关的类似问题,但这是 Google 找到的第一个结果,所以我将我的答案张贴在这里,以防其他人遇到同样的问题。

对我来说,问题是(如 ConnectionClosedException 明确指出的那样)在读取响应之前关闭 连接。类似的东西:

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);

try {
doSomthing();
} finally {
response.close();
}
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent(); // Response already closed. This won't work!

修复很明显。安排代码,以便响应在关闭后不被使用:

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet("http://localhost/");
CloseableHttpResponse response = httpclient.execute(httpget);

try {
doSomthing();
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent(); // OK
} finally {
response.close();
}

关于apache - org.apache.http.ConnectionClosedException : Premature end of chunk coded message body: closing chunk expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633549/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com