stef25
4 months ago
884
5
General

HTTP client configuration

Posted 4 months ago by stef25

The following call returns an error from the APi I'm calling, which is a POST call with no data.

$response = Http::withToken('xxx')->post('https://domain.com/api/account/1/get_stuff', []);
dd($response->body());

However the following CURL call as generated by Postman works fine.

curl --location --request POST 'https://domain.com/api/account/1/get_stuff' --header 'Authorization: Bearer xxx'

The problem, I think, lies with the fact that no data should be sent but a post() call in Laravel's HTTP client does expect a second parameter with the POST data. Whether I pass NULL or an empty array I always get an error back from the API.

How can I copy this curl call and get it to not send any data at all with the POST request?

Making the request with Guzzle works fine but I prefer the brevity of Laravel's HTTP client.

Please sign in or create an account to participate in this conversation.