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
239
votes
15 answers

How can I use Guzzle to send a POST request in JSON?

Does anybody know the correct way to post JSON using Guzzle? $request = $this->client->post(self::URL_REGISTER,array( 'content-type' => 'application/json' ),array(json_encode($_POST))); I get an internal server error…
user3379466
  • 3,087
  • 2
  • 14
  • 12
226
votes
3 answers

Guzzlehttp - How get the body of a response from Guzzle 6?

I'm trying to write a wrapper around an api my company is developing. It's restful, and using Postman I can send a post request to an endpoint like http://subdomain.dev.myapi.com/api/v1/auth/ with a username and password as POST data and I am given…
Greg
  • 6,453
  • 9
  • 45
  • 61
203
votes
6 answers

Guzzle 6: no more json() method for responses

Previously in Guzzle 5.3: $response = $client->get('http://httpbin.org/get'); $array = $response->json(); // Yoohoo var_dump($array[0]['origin']); I could easily get a PHP array from a JSON response. Now In Guzzle 6, I don't know how to do. There…
rap-2-h
  • 30,204
  • 37
  • 167
  • 263
175
votes
10 answers

Handle Guzzle exception and get HTTP body

I would like to handle errors from Guzzle when the server returns 4xx and 5xx status codes. I make a request like this: $client = $this->getGuzzleClient(); $request = $client->post($url, $headers, $value); try { $response = $request->send(); …
domos
  • 1,954
  • 2
  • 12
  • 12
146
votes
5 answers

PHP GuzzleHttp. How to make a post request with params?

How to make a post request with GuzzleHttp( version 5.0 ). I am trying to do the following: $client = new \GuzzleHttp\Client(); $client->post( 'http://www.example.com/user/create', array( 'email' => 'test@gmail.com', 'name'…
Arsen
  • 3,541
  • 4
  • 14
  • 7
106
votes
9 answers

Catching exceptions from Guzzle

I'm trying to catch exceptions from a set of tests I'm running on an API I'm developing and I'm using Guzzle to consume the API methods. I've got the tests wrapped in a try/catch block but it is still throwing unhandled exception errors. Adding an…
Eric
  • 1,253
  • 2
  • 10
  • 15
91
votes
4 answers

How to ignore invalid SSL certificate errors in Guzzle 5

This should be an easy thing to do. I can find plenty of references to how to do it in Guzzle 3, but they don't work in Guzzle 5. What I am doing so far: $this->client = new GuzzleClient(['defaults' => [ 'verify' => 'false' ]]); When I send a…
Gnuffo1
  • 3,478
  • 11
  • 39
  • 53
82
votes
8 answers

How do I do HTTP basic authentication using Guzzle?

I want to do basic access authentication using Guzzle and I am very new to programming. I have no clue what to do. I tried to do this using curl but my environment requires using guzzle.
Gopi K Mishra
  • 963
  • 1
  • 6
  • 5
77
votes
3 answers

PHP - Why Use Guzzle Instead of cURL?

In my application, I originally began using cURL to retrieve data from various APIs. Today, I tried using Guzzle to complete the same task. So far, both cURL and Guzzle seem to work equally good. Judging by Github, a lot of people seem to like…
Cato Minor
  • 2,992
  • 3
  • 29
  • 42
53
votes
5 answers

How to set default header in Guzzle?

$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…
Jürgen Paul
  • 14,299
  • 26
  • 93
  • 133
50
votes
7 answers

How to read the response effective URL in Guzzle ~6.0

I've been searching for about 2 hours and I can't figure it out how to read the final response uri. In previous versions of PHP Guzzle you just call $response->getEffectiveUrl() and you get it. I expected to have something similar in the new version…
joserobleda
  • 788
  • 1
  • 8
  • 12
46
votes
4 answers

Adding Query string params to a Guzzle GET request?

I read this answer but I believe there is a better way to create a http url query in Guzzle, I am looking for something like this, but cannot get it to work correctly, nor do I know if there is a way to dump the url string to see if it is processing…
ehime
  • 8,025
  • 14
  • 51
  • 110
42
votes
13 answers

Guzzle Curl Error 60 SSL unable to get local issuer

Trying to use the YouTube API v3 to get some video(s) information, using Guzzle in Symfony2 using Service Descriptors. When I run the script, I get this: [curl] 60: SSL certificate problem: unable to get local issuer certificate [url] …
RedactedProfile
  • 2,748
  • 6
  • 32
  • 51
37
votes
4 answers

Guzzle returns cURL error 3: malformed

I want to try out the guzzle library and am following through their quickstart tutorial to make http requests to an api. Yet it doesn't seem to work, because I get the following error: cURL error 3: malformed Since I have never worked with…
LoveAndHappiness
  • 9,735
  • 21
  • 72
  • 106
36
votes
4 answers

How can I send Cookies with Guzzlehttp/guzzle 6?

I need to send a request with custom cookies. I have tried to set cookieJar like this: $cookieJar = CookieJar::fromArray(array($cookieName=>$cookieStr), 'api.mobra.in'); $res =…
steve
  • 1,358
  • 5
  • 16
  • 26
1
2 3
99 100