Content-Length头已经presentContent、Length、present

由网友(矛盾)分享简介:我使用Apache的HttpClient(4.1)包含在Android的执行HttpPut。我已验证我只有1 Content-Length头。不过,我发送请求,每次,我得到已经指定的Content-Length头的协议例外。I am using the Apache HttpClient (4.1) included...

我使用Apache的HttpClient(4.1)包含在Android的执行HttpPut。我已验证我只有1 Content-Length头。不过,我发送请求,每次,我得到已经指定的Content-Length头的协议例外。

I am using the Apache HttpClient (4.1) included in Android to execute a HttpPut. I have verified that I only have 1 content-length header. However, every time I send the request, I get a protocol exception about the Content-Length header already specified.

HttpClient client = new DefaultHttpClient();
putMethod = new HttpPut(url + encodedFileName);
putMethod.addHeader(..)  //<-once for each header
putMethod.setEntity(new ByteArrayEntity(data));
client.execute(putMethod);  //throws Exception

产生的原因:org.apache.http.ProtocolException:Content-Length头已经present      在org.apache.http.protocol.RequestContent.process(RequestContent.java:70)      在org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:290)

Caused by: org.apache.http.ProtocolException: Content-Length header already present at org.apache.http.protocol.RequestContent.process(RequestContent.java:70) at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:290)

任何想法?

推荐答案

我没有用HttpClient的自己,但我怀疑的问题是, putMethod.setEntity(...)隐式地提供内容长度,你还明确通过的 putMethod.addHeader(...)调用中设置它。

I've not used HttpClient myself, but I suspect that the problem is that putMethod.setEntity(...) is implicitly supplying a content length and you are also setting it explicitly via one of the putMethod.addHeader(...) calls.

阅读全文

相关推荐

最新文章