Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpClient] Error 400 when making POST request #45735

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
DamienDub opened this issue Mar 14, 2022 · 1 comment
Closed

[HttpClient] Error 400 when making POST request #45735

DamienDub opened this issue Mar 14, 2022 · 1 comment

Comments

@DamienDub
Copy link

Symfony version(s) affected

5.4.5

Description

When making a simple HTTP POST request on RequestBin, a 400 status code is returned with the 5.4.5 version of the HttpClient library.
I does not happen with version 5.4.3.

It might be related to issue #45709

How to reproduce

Here is the Symfony command used to reproduce the issue:

<?php

namespace App\Command;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpClient\HttpClient;

class TestHttpCommand extends Command implements LoggerAwareInterface
{
    use LoggerAwareTrait;

    public function __construct()
    {
        parent::__construct();
    }

    protected function configure(): void
    {
        $this->setName('http:test')->setDescription('Test HTTP client');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $response = HttpClient::create()->request(
            'POST',
            'http://requestbin.net/r/3ez8hraq',
            [
                'body' => 'raw data',
            ]
        );

        $output->writeln("Status code: " . $response->getStatusCode()); // 200 with HttpClient 5.4.3, 400 with HttpClient 5.4.5

        return Command::SUCCESS;
    }
}

Possible Solution

No response

Additional Context

No response

@nicolas-grekas
Copy link
Member

Thanks for the report, closing as duplicate of #45709

nicolas-grekas added a commit that referenced this issue Apr 1, 2022
…quest headers (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] on redirections don't send content related request headers

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45709, #45735
| License       | MIT
| Doc PR        |

Commits
-------

d7c1361 [HttpClient] On redirections don't send content-related request headers
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