Denis Wróbel
Denis Wróbel

Reputation: 131

guzzlehttp, get request heders sent by GuzzleHttp\Client

How can I get headers sent by GuzzleHttp\Client()->get('URL')? I can only get response headers, but not request. Help! thanks.

Upvotes: 0

Views: 1261

Answers (1)

Vishnu Nair
Vishnu Nair

Reputation: 2433

You can call the getHeaders() method of Request to get all the headers in a request, if you want to specifically check for a header you can use hasHeader()

use GuzzleHttp\Psr7;

$request = new Psr7\Request('GET', 'URL', ['Foo' => 'Bar']);

//Check for a header
if ($request->hasHeader('Foo')) {
  echo 'Yes.';
}

//Get all the headers  
foreach ($request->getHeaders() as $name => $values) {
    echo $name .': ' . implode(', ', $values) . "\r\n";
}

Upvotes: 0

Related Questions