Symfony functional test - custom headers not passing through

前端 未结 2 683
囚心锁ツ
囚心锁ツ 2020-12-29 19:53

For some reason when i sent a new $client->request the headers I specify get lost:

public function testGetClientsAction()
{
    $client = static::createClien         


        
2条回答
  •  天涯浪人
    2020-12-29 20:33

    If you check the definition from Client.php, at method request, you will see in the docblock a very useful information:

    • @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)

    This means that you should add a HTTP_ prefix to the header you want to send. For example if you want to pass header X-HTTP-Method-Override you specify it like so:

        $client->request(
            Request::METHOD_POST,
            '/api/v1/something',
            $body,
            [],
            ['HTTP_X-HTTP-Method-Override' => Request::METHOD_GET]
        );
    

提交回复
热议问题