-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
HttpClient.PostAsJsonASync does not include a content-length header. #111659
Comments
Tagging subscribers to this area: @dotnet/ncl |
It shouldn't be set to 0, it should be using chunked encoding. Can you share a trace of it including the Content-Length header set to 0? It uses chunked encoding because it doesn't know the length the content will be when it starts to serialize it directly to the underlying stream. To know the length, it would need to buffer up the whole thing. |
Note the |
This issue has been marked |
Related to #49357
There are servers in the wild don't support chunked request body. https://stackoverflow.com/questions/30924004/php-how-to-read-post-body-with-transfer-encoding-chunked-no-content-length https://stackoverflow.com/questions/54444220/php-7-fpm-does-not-show-request-body-with-chunked-encoding |
Thank you for clarifying the behaviour. As my reproduction code also shows, there was no |
Description
When using
HttpClient.PostAsJsonAsync(value)
, the value ofContent-Length
is set to0
(EDIT: As shown in reproduction steps, aContent-Length
header is not present at all). This result in certain servers that receive the request fail to parse the request body.The cause for this behaviour seem to be that
JsonContent.TryComputeLength
always return 0 as the length of the content, opposed to e.g.StringContent
which return the length of the input.Reproduction Steps
Expected behavior
Request sent to server include a content-length header with a value of the actual content length.
Actual behavior
Request sent to server include a content-length header with a value of 0.
Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK 8.0.405
MacOS 15.2
ARM64
Other information
No response
The text was updated successfully, but these errors were encountered: