$baseUrl = 'http://foo'; $config = array(); $client = new Guzzle\Http\Client($baseUrl, $config);
What's the new way to set the default header for Guzzle without passing it as a parameter on every $client->post($uri, $headers)
?
There's $client->setDefaultHeaders($headers)
but it's deprecated.
setDefaultHeaders is deprecated. Use the request.options array to specify default request options
Guzzle, PHP HTTP client. Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc...
Debugging when using Guzzle, is quiet easy by providing the debug key in the payload: $client->request('GET', '/url, ['debug' => true]); This is quiet easy and not an issue if your are not passing any body content, using only query string to dump what's been request.
If you have a queued job that uses Guzzle to make a request, make sure you set a timeout value for the guzzle request: (new \GuzzleHttp\Client())->get('http://domain.com', [ 'timeout' => 15 ]);
You can use the getStatusCode function. $response = $client->request('GET', $url); $statusCode = $response->getStatusCode(); Note: If your URL redirects to some other URL then you need to set false value for allow_redirects property to be able to detect initial status code for parent URL.
If you are using Guzzle v=6.0.*
$client = new GuzzleHttp\Client(['headers' => ['X-Foo' => 'Bar']]);
read the doc, there are more options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With