skip to Main Content

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(IlluminateHttpClientRequest $request) {
    $request->toPsrRequest()
        ->withHeader('User-Agent', 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0');
});

2

Answers


  1. Chosen as BEST ANSWER
    Http::beforeSending(function(IlluminateHttpClientRequest $request) {
        dd((new NamshiCuzzleFormatterCurlFormatter)->format($request->toPsrRequest()));
    })->withOptions([
        'CURLOPT_USERAGENT' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0'
    ])->withHeaders([
        'Referer' => Request::fullUrl(),
        'X-Forwarded-For' => Request::ip()
    ])->get(self::URL)->json();
    

    Got nothing as User-Agent:

    curl 
      'https://uaas.yandex.ru/v1/exps?url=https%3A%2F%2Fwww.gdebar.ru%2Fbars%2Fkalininskaya%2Fmarksistskaya%2Fmandarin-na-taganke%3Fdebug%3D1&client_id=metrika.12521986' 
      -A 'GuzzleHttp/7' 
      -H 'Referer: https://www.gdebar.ru/bars/kalininskaya/marksistskaya/mandarin-na-taganke?debug=1' 
      -H 'X-Forwarded-For: 172.71.98.122'
    

  2. What about

    Http::withOptions([
        'CURLOPT_USERAGENT' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0',
    ]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search