DefaultHTTPClient +分块编码

时间:2013-10-24 17:16:13

标签: java scala apache-httpclient-4.x

org.apache.http.impl.client.DefaultHttpClient是否支持分块编码?

我无法弄清楚为什么我总能得到这个:

org.apache.http.TruncatedChunkException: Truncated chunk ( expected size: 16384; actual size: 13532)

Scala代码块:

val method = new HttpGet(uri)
val client = new DefaultHttpClient()
val response = client.execute(method)

Option(response.getEntity).foreach(
  body => {
    io.Source.fromInputStream(body.getContent).
      getLines().foreach(line => doStuff(line))
  }
  response.getEntity.getContent.close()
)

1 个答案:

答案 0 :(得分:0)

HttpClient完全支持块编码。您收到此异常是因为服务器发送的响应消息格式不正确。