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
34
votes
6 answers

cURL request in Laravel

I am struggling to make this cURL request in Laravel curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X GET http://my.domain.com/test.php I've been trying this: $endpoint =…
harunB10
  • 4,823
  • 15
  • 63
  • 107
34
votes
4 answers

Guzzle HTTP - add Authorization header directly into request

Can anyone explain how to add the Authorization Header within Guzzle? I can see the code below works for adding the username & password but in my instance I just want to add the Authorization header itself $client->request('GET', '/get', ['auth' =>…
Zabs
  • 13,852
  • 45
  • 173
  • 297
32
votes
2 answers

Guzzle: handle 400 bad request

I'm using Guzzle in Laravel 4 to return some data from another server, but I can't handle Error 400 bad request [status code] 400 [reason phrase] Bad Request using: $client->get('http://www.example.com/path/'.$path, [ …
mwafi
  • 3,946
  • 8
  • 56
  • 83
31
votes
3 answers

Upload file using Guzzle 6 to API endpoint

I am able to upload a file to an API endpoint using Postman. I am trying to translate that into uploading a file from a form, uploading it using Laravel and posting to the endpoint using Guzzle 6. Screenshot of how it looks in Postman (I purposely…
Brad
  • 12,054
  • 44
  • 118
  • 187
31
votes
3 answers

How to perform multiple Guzzle requests at the same time?

I can perform single requests using Guzzle and I'm very pleased with Guzzle's performance so far however, I read in the Guzzle API something about MultiCurl and Batching. Could someone explain to me how to make multiple requests at the same time?…
Martijn
  • 2,268
  • 3
  • 25
  • 51
29
votes
3 answers

Guzzle 6, get request string

Is there a way I can print out the full request as a string before or after it is sent? $res = (new GuzzleHttp\Client())->request('POST', 'https://endpoint.nz/test', [ 'form_params' => [ 'param1'=>1,'param2'=>2,'param3'=3 ] ] ); how can I view…
Nicekiwi
  • 4,567
  • 11
  • 49
  • 88
29
votes
4 answers

Using Guzzle to consume SOAP

I'm loving the Guzzle framework that I just discovered. I'm using it to aggregate data across multiple API's using different response structures. It's worked find with JSON and XML, but one the services i need to consume uses SOAP. Is there a…
LordZardeck
  • 7,953
  • 19
  • 62
  • 119
27
votes
1 answer

How to autoload Guzzle in Laravel 4?

How can I autoload Guzzle in Laravel 4? I am encountering the following error when I try to create a new GuzzleHttp/Client: Symfony \ Component \ Debug \ Exception \ FatalErrorException Class 'GuzzleHttp\Client' not found I have the following set…
Iain
  • 1,724
  • 6
  • 23
  • 39
25
votes
2 answers

Guzzle - Laravel. How to make request with x-www-form-url-encoded

I need to integrate an API so I write function: public function test() { $client = new GuzzleHttp\Client(); try { $res = $client->post('http://example.co.uk/auth/token', [ 'headers' => [ 'Content-Type' =>…
Aleks Per
  • 1,549
  • 7
  • 33
  • 68
25
votes
4 answers

How do I get the body of SENT data with Guzzle PHP?

I am using Guzzle (v6.1.1) in PHP to make a POST request to a server. It works fine. I am adding some logging functions to log what was sent and received and I can't figure out how to get the data that Guzzle sent to the server. I can get the…
ruhnet
  • 651
  • 1
  • 7
  • 14
25
votes
4 answers

How do you log all API calls using Guzzle 6

I'm trying to use guzzle 6 which works fine but I'm lost when it comes to how to log all the api calls. I would like to simply log timing, logged in user from session, url and any other usual pertinent info that has to do with the API call. I can't…
KingKongFrog
  • 13,946
  • 21
  • 75
  • 124
25
votes
3 answers

Can you include raw JSON in Guzzle POST Body?

This should be soo simple but I have spent hours searching for the answer and am truly stuck. I am building a basic Laravel application and am using Guzzle to replace the CURL request I am making at the moment. All the CURL functions utilise raw…
Jason Hill
  • 293
  • 1
  • 3
  • 6
25
votes
3 answers

GuzzleHttp\Client ignores base path in base_url

I'm using Guzzle in a set of PHPUnit-powered tests for a REST API. I create my client as follows: use GuzzleHttp\Client; $client = new Client(['base_url' => ['http://api.localhost/api/{version}', ['version' => '1.0']]]); This works fine, and I can…
Benjamin Nolan
  • 1,170
  • 1
  • 10
  • 20
23
votes
3 answers

Guzzle returns stream empty body instead of json body

When I use Postman to make an API call I receive a JSON object..which is what I expected. However When I make same call with Guzzle like so: $client = new \GuzzleHttp\Client(['base_uri' => 'https://api.dev/']); $response = $client->request('GET',…
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96
23
votes
5 answers

Send asynchronous request without waiting the response using guzzle

I have the following two functions public function myEndpoint(){ $this->logger->debug('Started'); $this->guzzle->requestAsync('post', 'http://myurl.com/doNotWait')->wait(); $this->logger->debug("I shouldn't wait"); } public function…
gmponos
  • 2,157
  • 4
  • 22
  • 33