guzzle6

Guzzle 6 - Get request total time

天涯浪子 提交于 2019-12-08 16:27:41
问题 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 a lot. 回答1: In Guzzle 6.1.0 You can use the 'on_stats' request option to get transfer time etc. More information can be found at Request Options - on_stats https://github.com/guzzle/guzzle/releases/tag/6.1.0 回答2: $client = new GuzzleHttp\Client();

Proper way to send (POST) xml with guzzle 6

和自甴很熟 提交于 2019-12-03 10:42:13
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 = new Client(); // $request = new Request('POST', $uri, [ 'body'=>$xml]); $response = $client->send($request); // //$code = $response->getStatusCode(); // 200 //$reason = $response->getReasonPhrase(); // OK // echo $response->getBody(); No matter what I try I get back error -1 which means that xml is not valid. XML that I send passes online validation

Guzzle6 error Invalid resource type: array when send a GuzzleHttp\Psr7\Request

六眼飞鱼酱① 提交于 2019-12-02 04:05:01
问题 I am trying to send a code by using GuzzleHttp\Psr7\Request,somehow I get error Invalid resource type: array, the following is my codes $params = ["name"=>"myName","id"=>"myId"]; $client = new Client(); $request = new Request('PUT','https://api.hitbox.tv/media/live/myName?authToken=myToken',["content-type"=>'application/json'],["json"=>$params]); $response = $client->send($request); I'm following this guide. 回答1: If you want to use JSON in the request, just create it with json_encode() :

Guzzle6 error Invalid resource type: array when send a GuzzleHttp\\Psr7\\Request

懵懂的女人 提交于 2019-12-01 23:00:36
I am trying to send a code by using GuzzleHttp\Psr7\Request,somehow I get error Invalid resource type: array, the following is my codes $params = ["name"=>"myName","id"=>"myId"]; $client = new Client(); $request = new Request('PUT','https://api.hitbox.tv/media/live/myName?authToken=myToken',["content-type"=>'application/json'],["json"=>$params]); $response = $client->send($request); I'm following this guide. If you want to use JSON in the request, just create it with json_encode() : $request = new Request( 'PUT', 'https://api.hitbox.tv/media/live/myName?authToken=myToken', ["content-type" =>

What's the correct way to use Guzzle 6 to create pool of asynchronous json requests to send to API endpoints?

柔情痞子 提交于 2019-12-01 18:14:39
My objective is to use Guzzle 6 to create a pool of asynchronous requests that PUT json data. Then monitor each $promise success/failure. For comparison to my POOL code example, the following single request to $client->request() converts the 3rd parameter to encoded json and then adds the Content-type:application/json.** $client = new Client([ 'base_uri' => BASE_URL . 'test/async/', // Base URI is used with relative requests 'timeout' => 0, // 0 no timeout for operations and watching Promises ]); $response = $client->request('PUT', 'cool', ['json' => ['foo' => 'bar']]); On the receiving API

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

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:33:08
问题 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( 'cookies' => true )); $response = $client->request('POST', 'http://myapi.com/login', [ 'timeout' => 30, 'form_params' => [ 'email' => $request->get('email'), 'password' => $request->get('password'), ] ]); and I get back the right response with a cookie, I can see

Guzzle async requests not really async?

╄→гoц情女王★ 提交于 2019-11-29 12:16:50
问题 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 these request synchronously rather than async. Expectation Just for test purposes, we are hitting an internal url, which does a 5 second sleep. With a concurrency of 10 we expect that all 10 requests will initially be queued and send to the server

Guzzle: Parallel file download using Guzzle's Pool:batch() and `sink` option

我怕爱的太早我们不能终老 提交于 2019-11-29 08:42:04
You can execute http requests in parallel using Guzzle's Pool:batch() method. It allows you to set default options for requests using options key in the third parameter. But what if I need different options for different requests in the pool? I would like to execute GET requests using a pool and stream each response to a different file on disk. There is a sink option for that. But how to apply different values of this option to requests? Rastor's example is almost right, but it's incorrectly implemented if you want to provide "options" to the Pool() constructor. He's missing the critical

Upload file using Guzzle 6 to API endpoint

旧巷老猫 提交于 2019-11-29 01:12:24
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 left out the POST URL) Below is the text it generates when you click the "Generate Code" link in POSTMAN: POST /api/file-submissions HTTP/1.1 Host: strippedhostname.com Authorization: Basic 340r9iu34ontoeioir Cache-Control: no-cache Postman-Token: 6e0c3123-c07c-ce54-8ba1-0a1a402b53f1 Content-Type: multipart/form-data; boundary=---

Guzzle: Parallel file download using Guzzle's Pool:batch() and `sink` option

这一生的挚爱 提交于 2019-11-28 02:02:17
问题 You can execute http requests in parallel using Guzzle's Pool:batch() method. It allows you to set default options for requests using options key in the third parameter. But what if I need different options for different requests in the pool? I would like to execute GET requests using a pool and stream each response to a different file on disk. There is a sink option for that. But how to apply different values of this option to requests? 回答1: Rastor's example is almost right, but it's