Skip to content

[HttpClient] Body is not sent if empty after 6.4.19 #59994

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

Closed
bettinz opened this issue Mar 17, 2025 · 4 comments
Closed

[HttpClient] Body is not sent if empty after 6.4.19 #59994

bettinz opened this issue Mar 17, 2025 · 4 comments

Comments

@bettinz
Copy link

bettinz commented Mar 17, 2025

Symfony version(s) affected

6.4.19

Description

Hi, I've this piece of code:

$response = $this->client->request(Request::METHOD_POST, $this->url, [
            'headers' => [
                'Content-Type' => 'application/json',
                'Authorization' => 'Bearer '.$token,
            ],
            'body' => [],
        ]);

Before 6.4.19 it was working. Now I see an error from the remote API that body is not sent.
I think it's related to #59763

How to reproduce

Update to 6.4.19, call a URL using POST and empty body

Possible Solution

No response

Additional Context

No response

@MatTheCat
Copy link
Contributor

An empty string is not valid JSON; this is probably why you get an error from your API. You should start by fixing that either by changing the Content-Type or the content depending on what the API expects.

@bettinz
Copy link
Author

bettinz commented Mar 17, 2025

You’re probably right @MatTheCat , what I’m trying to note here is that the behavior is changed in a minor release after a bug fixing release. And nowhere you can see a warning about that.
Also, if I send an empty body you don’t see an error from the HttpClient package, so it seems legit to use that.
I think it’s better to ask ourselves if this bug fix create a collateral effect and it’s expected or not.

@nicolas-grekas
Copy link
Member

#59763 is actually fixing a regression: what you see as a new behavior is actually restoring a previous one, and a correct one.
You should fix you code, sorry :)

@bettinz
Copy link
Author

bettinz commented Mar 17, 2025

Thanks for the explanation @nicolas-grekas 🙏

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

No branches or pull requests

4 participants