Skip to content
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

411 error on POST with empty body #838

Closed
djc opened this issue Mar 4, 2020 · 4 comments
Closed

411 error on POST with empty body #838

djc opened this issue Mar 4, 2020 · 4 comments

Comments

@djc
Copy link
Contributor

djc commented Mar 4, 2020

I get a 411 Length Required error from Azure with "The request must be chunked or have a content length." when sending a POST request with a .body(""). In this case, since I am explicitly setting a body, I would expect that Content-Length: 0 gets sent.

@seanmonstar
Copy link
Owner

Request semantics are defined such that the lack of a length header means the body is empty. For many servers, that's fine, and so the extra header doesn't need to be written.

If you want to force the header, you could call .header("content-length", 0).

@djc
Copy link
Contributor Author

djc commented Mar 4, 2020

I guess that's fine. I was surprised that a zero-length body is treated exactly the same as no body at all, though.

@djc djc closed this as completed Mar 4, 2020
@DouglasLivingstone
Copy link

If you want to force the header, you could call .header("content-length", 0).

Thanks, this worked for me. I started getting 411 responses from IIS after upgrading from reqwest 0.9.22 to reqwest 0.10.4. Changing from .body("") to .header("content-length", 0) resolved the issue.

@djc
Copy link
Contributor Author

djc commented Sep 2, 2024

I just ran into an issue with this again. I checked RFC 9110 and found:

A user agent SHOULD send Content-Length in a request when the method defines a meaning for enclosed content and it is not sending Transfer-Encoding. For example, a user agent normally sends Content-Length in a POST request even when the value is 0 (indicating empty content). A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data.

As such, I still think it would be an improvement to add this to relevant requests implicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants