从 HttpEntity 读取分块数据
我有以下代码:
HttpClient FETCHER
HttpResponse response = FETCHER.execute(host, httpMethod);
我试图将其内容读取为这样的字符串:
HttpEntity entity = response.getEntity();
InputStream st = entity.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(st, writer);
String content = writer.toString();
问题是,当我获取 时http://www.google.co.in/页面,传输编码被分块,我只得到第一个块。它获取直到第一个“”。
我如何一次获取所有块,以便我可以转储完整的输出并对其进行一些处理?
I have the following code:
HttpClient FETCHER
HttpResponse response = FETCHER.execute(host, httpMethod);
Im trying to read its contents to a string like this:
HttpEntity entity = response.getEntity();
InputStream st = entity.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(st, writer);
String content = writer.toString();
The problem is, when i fetch http://www.google.co.in/ page, the transfer encoding is chunked, and i get only the first chunk. It fetches till first "".
How do i get all the chunks at once so i can dump the complete output and do some processing on it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不应该使用 writeTo 吗?
文档说:
Shouldn't you use writeTo?
The docs say: