4 months ago

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('', []);

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

curl --location --request POST '' --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.