Questions tagged [guzzle6]

337 questions
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
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
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
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
27
votes
1 answer

Guzzle async requests not really async?

Problem We are trying to do concurrent asynchronous requests using guzzle. After going through a few resources, like this and this, we came up with some code that is shared below. However it is not working as expected. It looks like Guzzle is doing…
Scalable
  • 1,550
  • 4
  • 16
  • 29
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
24
votes
2 answers

PHP Guzzle with basic auth and bearer token

I'm trying to make a connection with infojobs-api, the documentation explian how to make it in this way: GET /api/1/application HTTP/1.1 Host: api.infojobs.net Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==,Bearer…
Oskar Calvo
  • 584
  • 1
  • 6
  • 22
24
votes
2 answers

What is the point of Guzzle async promises?

With Guzzle, do promises provide any real utility? It seems that you must call wait(). The following code (from the docs) seems to do nothing by itself: $promise = $client->requestAsync('GET', 'http://httpbin.org/get'); $promise->then( function…
originalbryan
  • 1,027
  • 1
  • 13
  • 21
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
20
votes
6 answers

Proper way to send (POST) xml with guzzle 6

I want to perform a post with guzzle sending an xml file. I did not find an example. What I 've done so far is : $xml2=simplexml_load_string($xml) or die("Error: Cannot create object"); use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $client…
user3485417
  • 583
  • 2
  • 7
  • 21
17
votes
4 answers

Queuing Guzzle Requests With Limits

I'm working on a Laravel application, using Guzzle 6. A lot of functionality relies on an API, of which I've created a wrapper for. My wrapper's a single class, that creates the Guzzle client in the __construct(), and has a variety of public…
Daniel Dewhurst
  • 2,533
  • 2
  • 21
  • 39
16
votes
3 answers

Guzzle 6 download file

Need help using Guzzle 6 for downloading a file from a rest API. I don't want the file to be saved locally but downloaded from web browser. Code so far below, but believe I am missing something?
Kevin Lindmark
  • 1,155
  • 3
  • 13
  • 26
15
votes
2 answers

Guzzle not behaving like CURL

I want to migrate from pure CURL to Guzzle, but the API calls are not being registered correctly. Working CURL (Class from here: https://stackoverflow.com/a/7716768/8461611) ... $Curl = new CURL(); // setting all curl_opts there // creating…
rndus2r
  • 496
  • 4
  • 17
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
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
1
2 3
22 23