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
13
votes
2 answers

GuzzleHttp\Client change base url dynamically

I am working on a project with a restful API. I use GuzzleHttp library in order to get/put etc. data in the API. Is there any way where you can change GuzzleHttp\Client's base url on the run. My idea is because I have multiple endpoints of one api…
Simeon Kolev
  • 606
  • 1
  • 4
  • 17
12
votes
2 answers

Use Guzzle to HTTP GET to external API with Symfony

I am new to Symfony development so excuse me if this is a dumb question. I am trying to GET JSON data from an external API. I have tried to run a GET request via Postman and got the correct data in JSON format back so I know my URL is correct. I…
Liz
  • 1,008
  • 5
  • 19
  • 49
12
votes
3 answers

How to get past login screen on Guzzle call

I have to send information to an external website using cURL. I set up Guzzle on my Laravel application. I have the basics set up, but according to the documentation of the website, there is an action that's required for the username and password.…
Lynx
  • 1,462
  • 5
  • 32
  • 59
12
votes
5 answers

sending array via query string in guzzle

Guzzle client creates by default from this code $client->get('https://example.com/{?a}', array('a' => array('c','d'))); this url https://example.com/?a=c,d What is the best practice to send array in query string in RESTful application? The…
Peter Krejci
  • 3,182
  • 6
  • 31
  • 49
12
votes
3 answers

Building query string programmatically in Guzzle?

In my PHP Guzzle client code, I have something like $c = new Client('http://test.com/api/1.0/function'); $request = $c->get('?f=4&l=2&p=3&u=5'); but instead I want to have something like: $request->set('f', 4); $request->set('l',…
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
11
votes
2 answers

Mailchimp addListMember returns client error 400 bad request when already existing

I'm working on adding a basic Mailchimp subscribe form to a website using their MailchimpMarketing\ApiClient() composer resource. Adding a user seems to work fine, but when trying to add somebody who already exists, i'd expect just a nice json…
Matdragon
  • 169
  • 1
  • 7
11
votes
5 answers

Guzzle Pool : Wait for Requests

Is it possible to make the Guzzle pool wait for requests? Right now I can add requests to the pool dynamically, but as soon as the pool is empty, guzzle will stop (obviously). This is a problem when I'm doing 10 or so pages concurrently, because my…
user429620
11
votes
3 answers

Using Guzzle promises asyncronously

I am attempting to use guzzle promises in order to make some http calls, to illustrate what I have, I have made this simple example where a fake http request would take 5 seconds: $then = microtime(true); $promise = new Promise( function() use…
Rich
  • 173
  • 1
  • 2
  • 8
11
votes
5 answers

Guzzle 6 - Get request total time

I'm searching to retrieve the request total time in Guzzle 6, just after a simple GET request : $client = new GuzzleHttp\Client(); $response = client->get('http://www.google.com/'); But can't find anything in the docs about that. Any idea ? Thanks…
Benoth
  • 111
  • 1
  • 1
  • 3
11
votes
1 answer

How to make create batch request in Guzzle6?

I need to send multiple requests so I want to implement a batch request. How can we do it in Guzzle6? Using the the old way: $client->send(array( $client->get($courses), //api url $client->get($job_categories), //api url )); is giving me…
RahulG
  • 1,028
  • 1
  • 15
  • 27
11
votes
3 answers

Can't set Guzzle Content Type

I'm trying to request this way: $body = []; $body['holder_name'] = $full_name; $body['bank_code'] = $bank_number; $body['routing_number'] = $branch_number; $body['account_number'] = $account_number; $body['type'] = 'checking'; $client = new…
Bug
  • 501
  • 1
  • 5
  • 11
11
votes
3 answers

Moving Curl client ssl to Guzzle

I'm using Guzzle v3.9.2 with both php 5.3 and php 5.5. I have the following working curl code that uses an ssl client certificate: $url = "https://example.com/"; $cert_file = '/path/to/certificate.pem'; $ch = curl_init(); $options = array( …
greggles
  • 2,089
  • 5
  • 20
  • 38
10
votes
5 answers

Guzzle throwing RejectionException instead of ConnectionException on background process

I have jobs that run on multiple queue workers, that contain some HTTP requests using Guzzle. However, the try-catch block inside this job does not seem to pick up GuzzleHttp\Exception\RequestException when I am running these job in the background…
Flame
  • 6,663
  • 3
  • 33
  • 53
10
votes
1 answer

Make Guzzle trust self-signed certificate?

With Guzzle HTTP client I know you can set new GuzzleClient(['verify' => false]) to have it not check the certificate, eg. when you are using a self-signed certificate. But how can I make it accept and trust a specific self-signed certificate, so…
TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64
10
votes
1 answer

Guzzle getContents()->getBody() - Second calls return empty string

I'm calling an API via Guzzle. public function request(string $method, string $uri, array $data = [], array $headers = []) { $response = $this->getClient()->$method($uri, [ 'headers' => $headers, 'query' => $data, ]); …
sineverba
  • 5,059
  • 7
  • 39
  • 84