-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
org.apache.http.ProtocolException: Content-Length header already present #454
Comments
I met the exception too. |
I'm not supplying the Content-Length anywhere in my code, but because it's a Multipart message it's is added for each part of the message, and I think since it's added at this point also the exception is thrown. As a test I added to the if clause a check that prevents adding the "Content-Length" if it's a Multipart message and this seems to solve the issue. |
Sorry, I means the Content-Length header was added by retrofit (In POST request). |
I would like to get an opinion from someone more experienced with Retrofit and correct HTTP requests.
But I don't know if this is a valid solution for all cases and additionally I needed to fix some test cases that are expecting to find "Content-Length". |
I'm having the same problem too connecting to a https service..Not sure what to do now |
Same problem here, I'm using last version of RoboSpice-Retrofit module (It uses Retrofit 1.5), and my App is crashing in all POSTs (JSON too). We have implemented our own ApacheClient, so we are getting this exception: http://docjar.org/docs/api/org/apache/http/protocol/RequestContent.html: if (request.containsHeader(HTTP.CONTENT_LEN)) { We don't use OkHttp because of SSL Exception, it crashes when it's combined with GAnalytics lib, and we don't use HttpURLConnection because of GZIP + Cache decoding bug. Our solution was stay at Retrofit 1.4.1 version, it's working OK. |
Found a way around it.. similar approach you used On 23 April 2014 16:43, Nicolas Giagnoni notifications@github.com wrote:
Opinions expressed in this email are those of the writer and not |
It would be great if someone can review the change I suggested and we can create a fix for the next release. |
I just hit this as well, on a POST to an SSL server. |
A ghetto fix: public class AndroidApacheClient extends retrofit.client.ApacheClient {
public AndroidApacheClient() {
super(AndroidHttpClient.newInstance("Retrofit"));
}
@Override
public Response execute(Request request) throws IOException {
List<retrofit.client.Header> headers = request.getHeaders();
List<retrofit.client.Header> modified = new ArrayList<retrofit.client.Header>();
for (int i = 0; i < headers.size(); i++) {
retrofit.client.Header header = headers.get(i);
if (!header.getName().equals("Content-Length")) {
modified.add(header);
}
}
return super.execute(new Request(request.getMethod(), request.getUrl(), modified, request.getBody()));
}
} |
OkHttp was locking up on thread waits, so I switched to ApacheClient and now this. Argh. Tried the ghetto fix above, back to locked up threading issues. Is there a more reliable older release? |
I think that Version 1.5 breaks MultipartTypedOutput:
I'm trying to send a File or ByteArray to the server and getting the "Content-Length header already present" error.
As far as I can see the relevant change was added in RequestBuilder adding Content-Length header.
https://github.com/square/retrofit/blob/master/retrofit/src/main/java/retrofit/RequestBuilder.java
from line 326:
The text was updated successfully, but these errors were encountered: