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

Set "Content-Length: 0" request header when request body is null on POST requests #171

Closed
beroso opened this issue Oct 22, 2018 · 2 comments
Labels
Milestone

Comments

@beroso
Copy link

beroso commented Oct 22, 2018

I'm using the CurlTransport, so maybe it's related to my cURL version.
I needed to make a post request to a API without body params, and the server responded with 400 status code.
It seems that HTTP POST requests requires a Content-Length header.

To overcome the problem, I sent a empty string as data:

$invoiceId = 'E58046425FA3472089A67A417D2AEF5D';
// ...
    ->setUrl('https://example.api/v1/' . $invoiceId . '/send_email')
    ->setMethod('post')
    ->setData('')
    ->send();
// ...

But it smells like a workaround to me :) .

I think it can be automatically set when preparing the request, to avoid the cURL bug.

Additional info:
cURL version: 7.29.0
PHP: 7.1.13

@samdark samdark added the type:bug Bug label Oct 22, 2018
@samdark
Copy link
Member

samdark commented Oct 22, 2018

That's correct.

@samdark samdark added the status:ready for adoption Feel free to implement this issue. label Oct 22, 2018
alexkart added a commit to alexkart/yii2-httpclient that referenced this issue Apr 17, 2019
@alexkart
Copy link
Contributor

alexkart commented Apr 17, 2019

HTTP headers sent before:

POST /user/test HTTP/1.1
Host: app.test
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Expect: 100-continue

after the fix:

POST /user/test HTTP/1.1
Host: app.test
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 0

@samdark samdark added this to the 2.0.9 milestone Apr 18, 2019
@samdark samdark added status:under development Someone is working on a pull request. and removed status:ready for adoption Feel free to implement this issue. labels Apr 18, 2019
@samdark samdark removed the status:under development Someone is working on a pull request. label Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants