-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Multipart - how to disable Content-Length for a part? #2604
Comments
@rafakob I think the workaround would be to copy/paste MultipartBody into your project and remove the code that adds the Content-Length. |
But Retrofit's |
You might not be able to use Retrofit for this. |
Ok, so I've commented out lines 157-159 in my Anyway, did anyone else report similar issues? If so, maybe it would be a good idea to make that header optional? |
You’re the only one. You should petition the owner of the server who has this limitation to fix their server so we don’t have to fix our client. |
This is not a server issue but actually a problem on the client. Non of the RFC handling multipart/form-data do allow Content-Length as a header field for individual parts. https://www.ietf.org/rfc/rfc1867.txt has this:
And the HTTP spec mentions the following:
The server may be a bit strict rejecting the POST but the client should not send it in the first place and just gets lucky that other servers are ignoring the field. |
Not quite. A more accurate statement would be that none of them require, define the semantics of, mention, and certainly do not forbid a Content-Length header in a body part. RFC 2046 also states:
|
@swankjesse actually,he is not the only one. |
same request here |
Another same request |
same request, please |
Yeah i have the same request here, please |
Would be great here too ! :) |
The reality is that because of this issue okhttp cannot be used as is with many existing APIs |
+1 |
That isn't what this issue is tracking. This is just for the inclusion or exclusion of the header when known. |
@swankjesse when to expect this enhancement? As I see 3.13 milestone was overdue. |
@code-n-roll this might get you unstuck:
Use it like this:
|
No further action to take on this. |
I wanted to remove the
Use the method like so:
|
Same request here. The |
This causes our users grief: #2604 #2138 I've resisted removing it because it seemed like it'd break compatibility in a significant way. But with OkHttp 5 it's a good time to break compatibility. As far as I can tell the behavior of including Content-Length in multipart bodies is not performed by web browsers or other HTTP clients.
This causes our users grief: #2604 #2138 I've resisted removing it because it seemed like it'd break compatibility in a significant way. But with OkHttp 5 it's a good time to break compatibility. As far as I can tell the behavior of including Content-Length in multipart bodies is not performed by web browsers or other HTTP clients.
FYI, We're dropping this bad behavior in 5.0. |
Question:
How to disable
Content-Length
header for a part? I need to do this because an API that I'm using does not allow it (and I can't do anything about it).I'm sure that the problem is that header, because I've tried to upload a file manually using
HttpURLConnection
and it works great withoutContent-Length
, and it fails immediately when I add it.I've tried to add interceptor to the request (both
addInterceptor
andaddNetworkInterceptor
) in order to remove unwanted header. But it is not here (I can see onlyContent-Disposition
). Is there another way to disable it?Mentioning
#2138
The text was updated successfully, but these errors were encountered: