Android HttpClient 问题设置内容长度



我试图创建一个包含以下内容的帖子...

HttpPost httppost = new HttpPost(URL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httppost.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
String length = String.valueOf(httppost.getEntity().getContentLength());
httppost.setHeader(HTTP.CONTENT_LEN, length); //If commented out it works

但是当我尝试运行请求时,出现以下错误...

10-11 22:05:02.940: W/System.err(4203(: org.apache.http.client.ClientProtocolException

我猜这是因为内容长度错误。

Apache HttpClient(甚至它随Android一起提供的分支(总是根据附带的HTTP实体的属性计算内容长度。不需要(也不应该(手动设置Content-LengthTransfer-Encoding标头。

最新更新