Laravel Http Client User-Agent header as -A

179 Views Asked by At

How can I pass User-Agent header with a especial curl parameter -A, not -H?

official curl docs

This code adds User-Agent with -H parameter, not -A:

Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0'])

This code has no effect:

Http::beforeSending(function(Illuminate\Http\Client\Request $request) {
    $request->toPsrRequest()
        ->withHeader('User-Agent', 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0');
});
1

There are 1 best solutions below

1
On

What about

Http::withOptions([
    'CURLOPT_USERAGENT' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0',
]);