Questions tagged [guzzle]

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Guzzle can be used with cURL, PHP's stream wrapper, sockets, and non-blocking libraries like React.

Guzzle is a PHP HTTP client & framework for building RESTful web service clients.


Features:

  • Extremely powerful API provides all the power of cURL with a simple interface.
  • Truly take advantage of HTTP/1.1 with persistent connections, connection pooling, and parallel requests.
  • Service description DSL allows you build awesome web service clients faster.
  • Symfony 2 event-based plugin system allows you to completely modify the behavior of a request.
  • Includes a custom Node.js web server to test your clients. Unit-tested with PHPUnit with 100% code coverage.

Documentation:

2576 questions
16
votes
7 answers

GuzzleHttp Hangs When Using Localhost

Here is a simple code snipplet but this just hangs and unresponsive. $httpClient = new GuzzleHttp\Client(); // version 6.x $headers = ['X-API-KEY' => '123456']; $request = $httpClient->request('GET',…
spreaderman
  • 918
  • 2
  • 10
  • 39
16
votes
6 answers

Installation Guzzle in Laravel 5

how to Install Guzzle into Laravel 5? I'm using laravel for my project, but I need library like guzzle to made me easy using curl in laravel. Any Body can help?
Rahman
  • 1,051
  • 2
  • 8
  • 11
15
votes
2 answers

How to add headers in Guzzle http

I'm building a small application in Laravel 5.5 where I'm using Guzzle Http to get call the api url and get the response, Few of the api calls have certain condition to have headers which works as authorization of the request generated. I'm trying…
rajesh
  • 239
  • 2
  • 6
  • 21
15
votes
4 answers

Retrieve the whole XML response body with Guzzle 6 HTTP Client

I wanted to use Guzzle 6 to retrieve an xml response from a remote API. This is my code: $client = new Client([ 'base_uri' => '', ]); $response = $client->get('', [ 'query' => [ 'token' => '', ], …
luqo33
  • 8,001
  • 16
  • 54
  • 107
14
votes
2 answers

How to Retrieve HTTP Status Code with Guzzle?

New to Guzzle/Http. I have a API rest url login that answer with 401 code if not authorized, or 400 if missing values. I would get the http status code to check if there is some issues, but cannot have only the code (integer or string). This is my…
sineverba
  • 5,059
  • 7
  • 39
  • 84
14
votes
3 answers

Laravel Unresolvable dependency resolving [Parameter #0 [ $method ]] in class GuzzleHttp\Psr7\Request

When posting form I am getting this exception Unresolvable dependency resolving [Parameter #0 [ $method ]] in class GuzzleHttp\Psr7\Request Searched and tried many ways to solve this but no progress. Seems that my problem is same as this…
Ansib Raza
  • 388
  • 2
  • 3
  • 11
14
votes
3 answers

How to retrieve cookies from Guzzle client?

How can I retrieve the cookies from a Guzzle request / client, after a request has occurred? $client = new Client([ 'base_uri' => 'www.google.com', ]); $response = $client->request('GET', '/');
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
14
votes
5 answers

Curl error : No route to host

So we're building a web application in PHP and we're trying to make requests to an external API. Problem is that we're getting a curl error: cURL error 7: Failed to connect to external.api.com port 443: No route to host A little bit of background…
Mihkel Allorg
  • 929
  • 1
  • 8
  • 26
14
votes
5 answers

GuzzlePHP mock response content

I want to mock a response to the Guzzle request: $response = new Response(200, ['X-Foo' => 'Bar']); //how do I set content of $response to--> "some mocked content" $client = Mockery::mock('GuzzleHttp\Client'); …
Tzook Bar Noy
  • 11,337
  • 14
  • 51
  • 82
13
votes
4 answers

Prestashop Guzzle Conflict

I am updating a prestashop module by including a package that uses guzzle6.0. Prestashop 1.7 uses an older version of Guzzle 5. When I install the plugin on Prestashop the included package's version of Guzzle conflicts with the Prestashop one…
Jonny C
  • 1,943
  • 3
  • 20
  • 36
13
votes
4 answers

PHPUnit and mock request from Guzzle

I have a class with the following function : public function get(string $uri) : stdClass { $this->client = new Client; $response = $this->client->request( 'GET', $uri, $this->headers ); return…
themazz
  • 1,107
  • 3
  • 10
  • 29
13
votes
2 answers

Firestore REST API: Query parameters type of object

I am looking for an advice regarding Google Firestore REST API I am trying to update the document but keep the data that are not updated (https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.documents/patch) I have a…
Ondřej Rehák
  • 573
  • 5
  • 12
13
votes
2 answers

GuzzleHttp:how can I save cookies from a POST response and use it in the next POST?

I'm using Guzzle to login my API site, and in the moment Im login with the right credentials, I get back a cookie with a RefreshToken to send it in the next call, here is my simple (and working well) code: $client = new Client(array( …
Eran Levi
  • 877
  • 2
  • 12
  • 31
13
votes
2 answers

Laravel environment variables leaking between applications when they call each other through GuzzleHttp

I have two Laravel 5.2 applications (lets call them A and B) on my local machine, both configured on two different virtualhosts on my local Apache 2.4 development server. Both applications sometimes are calling each other through GuzzleHttp. At one…
JustAMartin
  • 13,165
  • 18
  • 99
  • 183
13
votes
2 answers

Passing cookies from browser to Guzzle 6 client

I have a PHP webapp that makes requests to another PHP API. I use Guzzle to make the http requests, passing the $_COOKIES array to $options['cookies']. I do this because the API uses the same Laravel session as the frontend application. I recently…
Thelonias
  • 2,918
  • 3
  • 29
  • 63