guzzle

Unit Testing Guzzle inside of Laravel Controller with PHPUnit

谁说胖子不能爱 提交于 2019-12-19 03:15:58
问题 I'm not quite sure which way to approach unit testing in this scenario. None of the examples for unit testing Guzzle quite make sense to me how to implement in this scenario, or perhaps I'm just looking at it incorrectly all together. The setup: Laravel 4.2 REST API - A controller method is using Guzzle in the method to request data from another api as follows: <?php class Widgets extends Controller { public function index(){ // Stuff $client = new GuzzleHttp\Client(); $url = "api.example.com

How to crawl with php Goutte and Guzzle if data is loaded by Javascript?

南楼画角 提交于 2019-12-19 02:43:04
问题 Many times when crawling we run into problems where content that is rendered on the page is generated with Javascript and therefore scrapy is unable to crawl for it (eg. ajax requests, jQuery) 回答1: You want to have a look at phantomjs. There is this php implementation: http://jonnnnyw.github.io/php-phantomjs/ if you need to have it working with php of course. You could read the page and then feed the contents to Guzzle, in order to use the nice functions that Guzzle gives you (like search for

How do we specify TLS/SSL options in Guzzle?

岁酱吖の 提交于 2019-12-18 19:17:26
问题 We are starting to use Guzzle in PHP with code which calls a variety of different APIs, a few of which don't support TLSv1.2 and some of which require TLSv1.2. What's the best way to force Guzzle to use the most recent protocol available, except in cases where we know it won't be recognized? 回答1: It is simple and easy. $client = new Client(); $guzzle = new GuzzleClient('https://www.yourweb.com', array( 'curl.options' => array( CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2 ) )); $client-

Looping PHP Nested Arrays - Extract values into Blade Views (Laravel)

橙三吉。 提交于 2019-12-18 17:04:43
问题 I know there are many questions on this topic, but none quite deal with this (as far as I could see). I have a PHP array (which FYI, is returned via Guzzle response) in a Laravel Project. The PHP array $users = array(2) { ["error"]=> bool(false) ["spirits"]=> array(2) { [0]=> array(2) { ["id"]=> string(1) "1" ["name"]=> string(5) "Foo" } [1]=> array(2) { ["id"]=> string(1) "2" ["name"]=> string(3) "Bar" } } } I simply want to extract the "id" and "name" keys below, to use in a view but I'm a

Guzzle: handle 400 bad request

谁都会走 提交于 2019-12-18 11:23:05
问题 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, [ 'allow_redirects' => true, 'timeout' => 2000 ]); how to solve it? thanks, 回答1: As written in Guzzle official documentation: http://guzzle.readthedocs.org/en/latest/quickstart.html A GuzzleHttp\Exception\ClientException is thrown for 400 level errors if the exceptions request

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

大憨熊 提交于 2019-12-17 02:42:17
问题 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 back a token. All works as expected. Now, when I try and do the same from PHP I get back a GuzzleHttp\Psr7\Response object, but can't seem to find the token anywhere inside it as I did with the Postman request. The relevant code looks like: $client

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

一个人想着一个人 提交于 2019-12-17 02:42:13
问题 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 back a token. All works as expected. Now, when I try and do the same from PHP I get back a GuzzleHttp\Psr7\Response object, but can't seem to find the token anywhere inside it as I did with the Postman request. The relevant code looks like: $client

Using PHP Guzzle HTTP 6 to send JSON with data that is already encoded

无人久伴 提交于 2019-12-14 04:17:59
问题 I am trying to send a POST request which contains a raw JSON string with the following header: Content-Type: application/json . From looking at the docs, I can see that I can do something like this... $data = ['x' => 1, 'y' => 2, 'z' => 3]; $client = new \GuzzleHttp\Client($guzzleConfig); $options = [ 'json' => $data, ]; $client->post('http://example.com', $options); My problem is that when I get to this point, $data has already been json_encode 'd. I have tried the following but it does not

Guzzle unable to bypass cURL error 35: SSL connect error

和自甴很熟 提交于 2019-12-13 16:19:55
问题 Using Guzzle 6 I am attempting to communicate with an Https endpoint that uses a self-signed certificate. I am instantiating my Client class as follows: $authClient = new Client([ 'base_uri' => config('app.auth_uri'), 'verify' => false ]); And attempting a request: $res = $this->authClient->request('POST', '/auth', [ 'form_params' => [ 'client_id' => 'XXXXXXXXXXXXXXX', 'username' => 'RSA', 'grant_type' => 'password' ] ]); Here is the error I get: cURL error 35: SSL connect error (see http:/

Guzzle 6 result returns with HTTP Headers

[亡魂溺海] 提交于 2019-12-13 14:17:10
问题 I'm having a problem with how Guzzle 6.x returns my results, due to this I am receiving "Syntax Error" when I try to json_decode my results. I have used var_dump() and print_r() to get my actual results and it turns out that my JSON results returns with a HTTP Header included in it. Actual results below: string(486) "Array ( [Content-Type] => application/json [Content-Length] => 23 [X-Auth-Key] => XXXXXXXXXXXXXXXXXXXXXXX [X-Apikey] => XXXXXXXXX [User-Agent] => GuzzleHttp/6.3.3 curl/7.54.0 PHP