10000 [HttpClient] Error 400 when making POST request · Issue #45735 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpClient] Error 400 when making POST request #45735
Closed
@DamienDub

Description

@DamienDub

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0