- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在试用 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
传输编码 → 分块
任何人都可以指导我解决此异常并指出我是否遗漏任何内容或任何不正确的实现。
最佳答案
我有一个与 rest-assured 无关的类似问题,但这是 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/
我正在尝试使用 Node js 服务将 .json 文件的内容获取到 angularjs 方法中。但是我得到以下错误: _http_outgoing.js:700 throw new ERR_INVA
我使用的是 npm 版本 6.0.1。我的操作系统是 macOS High Sierra 版本 10.13.3 我想构建我的项目,但收到此错误消息: Creating an optimized pro
import numpy as np from matplotlib import pyplot as plt import scipy.io.wavfile as wav from numpy.li
下面是一段c++代码: Chunk * _chunk = new (size) Chunk(size); 我不明白'new'后面的第一个'(size)',它是什么意思?以上代码来自JDK8。 最佳答案
我有一个 RSS 提要。当我在打开 Fiddler Web Debugger 的情况下浏览提要时,Fiddler 向我抛出此错误: Chunked body did not terminate pro
当我运行脚本 npm run watch 时出现此错误 cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --wat
我在尝试启动我的应用程序时看到以下错误... > css-modules@1.0.0 start /Users/johnnynolan/Repos/css-modules webpack && ope
我正在使用 MVC 6 rc1 和 EF 7 rc 1 Code First 模型通过 Web API Controller 检索数据。我有 3 个类似于下面的表。 class Product {
我在一个 txt 文件中有以下数据: 00001+++00001 000031 12.8600 -1 7 BEAR 1990052418 276.0
我正在试用 RestAssured 并编写了以下语句 - String URL = "http://XXXXXXXX"; Response result = given().
我在 RMarkdown 文档中有一个块,如下所示: ```{r, echo=-4} a <- 1 b <- 2 x <- a + b print(paste(c("`x` is equal to "
这个迭代器 let data = vec![0, 1, 2, 3, 4, 5]; for x in data.chunks(2) { println!("{:?}", x); } 会产生 [0
flock() 的 PHP 文档页面表明在IIS下使用不安全。如果我不能在所有情况下都依赖 flock,是否有其他方法可以安全地实现同样的目标? 最佳答案 在所有想象的可能情况下,没有其他方法可以安全
我正在开发一个 Android 示例应用程序,它从 http://www.omdbapi.com/ 获取电影列表. REST 服务是: http://www.omdbapi.com/?s=star&a
我正在寻找 MemoryStream 的实现,它不会将内存分配为一个大块,而是一组 block 。我想在内存(64 位)中存储几 GB 的数据,并避免内存碎片的限制。 最佳答案 像这样: class
我们有一个 React 应用程序,它使用 React.lazy 和 Suspend 进行代码拆分。每个星期二我们都会部署一个新版本,因此我们的 block 也会发生变化。 我们现在遇到的问题是,如果我
我对Laravel的ORM Eloquent chunk()方法有疑问。 它错过了一些结果。 这是一个测试查询: $destinataires = Destinataire::where('statu
我需要知道是否可以将 iTextSharp 中的两个 Chunk 组合起来 Phrase phrase = new Phrase(); var text1 = new Chunk("hello");
我正在使用播放框架来生成分块响应。代码是: class Test extends Controller { public static void chunk() throws Interrup
这个问题已经有答案了: Split array into chunks (80 个回答) 已关闭 5 年前。 我正在尝试在 JavaScript 中实现一个类似于 lodash chunk 的 blo
我是一名优秀的程序员,十分优秀!