HttpClient body params not accepted

I am connecting my Symfony project with external server endpoint via HttpClient. I am getting desired response.

Problem occurs when I try to pass two parameters from my request body. When this endpoint is tested in Postman it works as it should.

It’s like the params are not included as I get the same response as without them. Response should return filtered results by dates I am inputing.

public function callIt($endpoint, $startDate, $endDate)
{
    $method = 'GET';
    $token = $this->authApi->getToken('test', 'test');

    $url = 'http://my-endpoint.oi' . $endpoint;

    $params = [
        'startDate' => $startDate,
        'endDate' => $endDate
    ];

    return HttpClient::create(['base_uri' => $url])->request($method, $url, [
        'headers' => [
            'Authorization' => 'Bearer ' . $token['access_token'],
        ],
        'body' => $params
    ]);
}

Also tried:

'body' => ['startDate' => 'value1', '...'],

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *