Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set referer header in Guzzle

Tags:

http

php

guzzle

I'm trying to set the referer header on a guzzle request, but when I analyze the request Chrome developer tools, the referer header is not in the list of request headers. This is how I set the header:

 $headers = ['referer' => 'test.referer.com'];
    $guzzle = new Client([
        'defaults' => ['headers' => $headers]
    ]);
    $result = $guzzle->get('http://google.com');
    return $result;

I have tried multiple other solutions, but it's still not working. What am I missing?

like image 573
hansn Avatar asked May 11 '16 14:05

hansn


1 Answers

if it v6

$headers = ['Referer' => 'test.referer.com'];
$guzzle = new \GuzzleHttp\Client([
    'headers' => $headers
]);
$result = $guzzle->get('http://google.com');
return $result;

You don't need strange param default

And need Referer. Not referer

like image 160
trijin Avatar answered Oct 19 '22 01:10

trijin