guzzle

Fatal error: Call to undefined method GuzzleHttp\Client::request() with Guzzle 6

拈花ヽ惹草 提交于 2019-11-28 07:29:02
问题 I'm using Guzzle 6 with Laravel 5.2. I'm trying to access a simple internal API: use GuzzleHttp\Client; $client = new Client(['base_uri' => getenv('URL_BASE').'api/v1/']); $response = $client->request('GET', 'tournaments'); And I get this message: Fatal error: Call to undefined method GuzzleHttp\Client::request() When I see the docs, it says: $client = new GuzzleHttp\Client(['base_uri' => 'https://foo.com/api/']); But PHPStorm cannot resolve GuzzleHttp What should I do to make it work??? 回答1:

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

How to perform multiple Guzzle requests at the same time?

大憨熊 提交于 2019-11-27 20:13:06
问题 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? Async if possible. I don't know if that is what they mean with MultiCurl. Sync would also be not a problem. I just want to do multiple requests at the same time or very close (short space of time). 回答1: From the docs: http://guzzle3.readthedocs.org

Catching exceptions from Guzzle

我只是一个虾纸丫 提交于 2019-11-27 17:29:32
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 event listener as described in their docs doesn't seem to do anything. I need to be able to retrieve the responses that have HTTP codes of 500, 401, 400, in fact anything that isn't 200 as the system will set the most appropriate code based on the result of the call if it didn't work. Current code example foreach($tests as $test){ $client = new

Guzzle returns cURL error 3: <url> malformed

扶醉桌前 提交于 2019-11-27 17:18:08
问题 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: <url> malformed Since I have never worked with cURL before, I don't even know how to respond to that error message. Here is my code with the request I am making: $client = new Client(); $client->get('/', ['verify' => true]); $response = $client->get('https://api.github.com/'); dd($response); I am

Guzzle 6 progress of download

回眸只為那壹抹淺笑 提交于 2019-11-27 14:49:32
I want to download a large file with Guzzle and want to track the progress. I don't know if I have to pass a stream or use the RequestMediator somehow. I tried with subscribing to the event curl.callback.progress, but the PSR 7 Request doesn't have an event dispatcher. I tried the on_stats , but the callback is only fired at the end. The progress subscriber plugin is deprecated https://github.com/guzzle/progress-subscriber I'm testing the following code. $dl = 'http://archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64/current/images/netboot/mini.iso'; $client = new Client([]); $request

How do you log all API calls using Guzzle 6

百般思念 提交于 2019-11-27 14:04:19
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 seem to find any documentation for Guzzle 6 that refers to this, only guzzle 3 (Where they've changed the logging addSubscriber call). This is how my current API calls are: $client = new GuzzleHttp\Client(['defaults' => ['verify' => false]]); $res = $client->get($this->url . '/api/details', ['form_params' => ['file' => $file_id]]); You can use any

How to autoload Guzzle in Laravel 4?

无人久伴 提交于 2019-11-27 11:44:32
问题 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 up in my composer.json autoload section: autoload: { "psr-0": { "Guzzle\\": "src/" } } 回答1: You don't need to add Guzzle to your composer.json, it's already autoloaded by it's own composer.json. Guzzle 4 PHP 5.4.x+ required composer require

Guzzle 6: no more json() method for responses

落花浮王杯 提交于 2019-11-27 11:09:31
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 seems to be no json() method anymore. I (quickly) read the doc from the latest version and don't found anything about JSON responses. I think I missed something, maybe there is a new concept that I don't understand (or maybe I did not read correctly). Is this (below) new way the only way? $response = $client->get('http://httpbin.org/get'); $array =

Handle Guzzle exception and get HTTP body

落爺英雄遲暮 提交于 2019-11-27 09:13:13
问题 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(); return $response->getBody(); } catch (\Exception $e) { // How can I get the response body? } $e->getMessage returns code info but not the body of the HTTP response. How can I get the response body? 回答1: Guzzle 3.x Per the docs, you can catch the