I've got a cron set up in my Laravel project that makes a GET request to an endpoint, I'd like to set my own customer user agent that this request uses so that it can easily be identified amongst other potential requests to the same server.
My current code within my function is:
$response = Http::timeout($timeout)->get($url);
$code = $response->getStatusCode();
I'd like to set a custom user agent for this request like so:
Mozilla/5.0+(compatible; EXAMPLE/2.0; http://www.EXAMPLE.com/)
Can't seem to find anything in the docs to suggest how to do this
Since Laravel v8.8 (this pull request) you can use the withUserAgent
method to set your own user agent.
Http::withUserAgent($userAgent)->get($url);
Before that you could set your own header like this:
Http::withHeaders(['User-Agent' => $userAgent])->get($url);