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
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)
Any ideas?
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 theputMethod.addHeader(...)calls.