I am trying to send an external post request in Laravel 9 using the official HTTP Client, and have run into a problem I cannot figure out. I've been testing the function several times, and based on what I see in the logs in Laravel Telescope, it randomly switches between sending GET and POST requests.
Long story short, my app listens to & parses incoming emails, and if it detects that it's a verification email from Google, it fetches the URL and sends an empty POST request. This lets my users set up auto-forwarding to my email service in Gmail without having to enter a verification code. GET requests don't work.
$response = Http::post($link[0]);
This is what shows up in Telescope after running multiple tests on the same code: Telescope HTTP Client log
I've tried adding a payload to the request, but the results are the same:
$response = Http::post($link[0],
[
'app' => 'appname'
]);
I have tried testing with a local docker (sail) environment, and also in a production environment with SSL/https. Results are the same.
I have noticed one small difference in the headers my app sends. Headers in POST requests:
{
"content-length": "2",
"user-agent": "GuzzleHttp/7",
"content-type": "application/json",
"host": "mail.google.com"
}
Headers in GET requests:
{
"host": "mail.google.com",
"user-agent": "GuzzleHttp/7",
"content-type": "application/json"
}
Is there anything I can do to "enforce POST"? Appreciative for any help I can get.