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

RequestOptions::JSON => $body doesn't add Content Type and Accept to body anymore #2745

Open
aligajani opened this issue Aug 16, 2020 · 6 comments
Labels
lifecycle/keep-open Issues that should not be closed

Comments

@aligajani
Copy link

Guzzle version(s) affected: ^6.3.1
PHP version: 7.3.2 (hint: php --version)
cURL version: 7.65.3 (hint: php -i | grep cURL)

Description
So I ran composer update a few hours ago and now RequestOptions::JSON => $body doesn't add Content Type and Accept to body anymore. When I run the following, it simply returns the HTML response on the API I am hitting because it expects JSON in the Content Type and Accept, which I thought the RequestOptions::JSON is intended to supply out of the box.

 logger('POST', compact('body', 'endpoint'));
            $client = new Client();

            $response = $client->post($this->apiUrl . $endpoint, [
                'headers'            => [
                    'Authorization' => 'Bearer' . " " . $this->apiKey
                ],
                RequestOptions::JSON => $body
            ]);

            logger($response->getHeaders());
@Nyholm Nyholm added this to the 8.0.0 milestone Oct 10, 2020
@Nyholm
Copy link
Member

Nyholm commented Oct 10, 2020

Let’s add the content type in guzzle 8

@stale
Copy link

stale bot commented Feb 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 2 weeks if no further activity occurs. Thank you for your contributions.

@stale stale bot added the lifecycle/stale No activity for a long time label Feb 7, 2021
@stale stale bot closed this as completed Feb 21, 2021
@mfn
Copy link

mfn commented Feb 22, 2021

Maybe stale bot shouldn't process issues added to milestones

@guilliamxavier
Copy link
Contributor

RequestOptions::JSON has never added the Accept header, cf its phpDoc:

json: (mixed) Adds JSON data to a request. The provided value is JSON encoded and a Content-Type header of application/json will be added to the request if no Content-Type header is already present.

As for the Content-Type, there was a possibly related change in 6.3.1 (#1916), but I just checked that it is correctly added in 6.5.5 for your example

@GrahamCampbell GrahamCampbell reopened this May 6, 2021
@stale stale bot removed the lifecycle/stale No activity for a long time label May 6, 2021
@GrahamCampbell GrahamCampbell added the lifecycle/keep-open Issues that should not be closed label May 6, 2021
@GrahamCampbell
Copy link
Member

There is a lifecycle label for this. :)

@guilliamxavier
Copy link
Contributor

To be clear, I didn't mean to have it reopened. For me there is no bug.

@GrahamCampbell GrahamCampbell removed this from the 8.0.0 milestone Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/keep-open Issues that should not be closed
Projects
None yet
Development

No branches or pull requests

5 participants