Content-Length头已经present [英] Content-Length header already present
问题描述
我使用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.
这篇关于Content-Length头已经present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!