guzzle

Guzzle cookies handling

£可爱£侵袭症+ 提交于 2019-11-30 05:47:49
I'm building a client app based on Guzzle. I'm getting stucked with cookie handling. I'm trying to implement it using Cookie plugin but I cannot get it to work. My client application is standard web application and it looks like it's working as long as I'm using the same guzzle object, but across requests it doesn't send the right cookies. I'm using FileCookieJar for storing cookies. How can I keep cookies across multiple guzzle objects? // first request with login works fine $cookiePlugin = new CookiePlugin(new FileCookieJar('/tmp/cookie-file')); $client->addSubscriber($cookiePlugin); $client

Guzzle and HTTPS

扶醉桌前 提交于 2019-11-30 05:30:00
问题 I want to use Guzzle and Silex to send request to https pages. With http url I have a response : app->get('/',function() use ($app, $client){ $response = $client->get("http://www.google.fr"); var_dump($response); }); My response: object(GuzzleHttp\Message\Response)[102] private 'reasonPhrase' => string 'OK' (length=2) private 'statusCode' => int 200 private 'effectiveUrl' => string 'http://www.google.fr' (length=20) private 'headers' (GuzzleHttp\Message\AbstractMessage) => array (size=13)

Guzzle: handle 400 bad request

我的梦境 提交于 2019-11-30 03:46:06
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, 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 option is set to true For correct error handling I would use this code: use GuzzleHttp\Client; use GuzzleHttp

Laravel environment variables leaking between applications when they call each other through GuzzleHttp

给你一囗甜甜゛ 提交于 2019-11-30 03:38:34
问题 I have two Laravel 5.2 applications (lets call them A and B) on my local machine, both configured on two different virtualhosts on my local Apache 2.4 development server. Both applications sometimes are calling each other through GuzzleHttp. At one point I wanted to use encryption and I started getting "mac is invalid" exceptions from Laravel's Encrypter. While investigating the issue, I found that when app A calls app B, app B suddenly gets encryption key (app.key) from app A! This causes

Php如何调用以太坊JSON RPC接口

蹲街弑〆低调 提交于 2019-11-29 18:54:05
以太坊规定了每个节点需要实现的JSON RPC应用开发接口,如果希望使用PHP开发一个以太坊区块链 上的去中心化应用(DApp),首先要解决的问题就是如何使用PHP调用 以太坊JSON RPC接口 : 如果你希望将网站快速接入以太坊,例如支持以太币支付,或者发行自己的代币,那么这个 Php以太坊开发详解 课程提供了最佳的学习路径。 虽然接口规范并没有对传输层进行约定,但大多数以太坊节点软件都实现了对HTTP协议的支持。 因此我们可以使用Php的HTTP开发包来进行调用。例如,下面的代码使用guzzle这个http开发包来获取以太坊节点旳版本信息: <?php $client = new GuzzleHttp\Client(); $opts = [ 'json' => [ 'jsonrpc' => '2.0', 'method' => 'web3_clientVersion', 'params' => [], 'id' => time() ] ]; $rsp = $client->post('http://localhost:8545',$opts); echo $rsp->getBody() . PHP_EOL; ?> 当然你也可以借助于一些开源的封装,不过在php社区中,目前还缺乏得到统一认可的、相对比较成熟的以太坊开发包,因此在DApp的开发过程中

PayPal IPN simulator returning “INVALID” but I've followed the rules

我是研究僧i 提交于 2019-11-29 16:47:15
So I have a PHP service that's only job is to accept PayPal IPN connections. I'm using PSR7 $request->getBody()->getContents() to get the following from PayPal IPN simulator request. payment_type=echeck&payment_date=Tue%20Jun%2007%202016%2012%3A56%3A47%20GMT+0100%20%28BST%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123

How to get email from facebook through Guzzle in laravel?

五迷三道 提交于 2019-11-29 16:09:53
I am using below code to login via facebook in laravel. Referring https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps for token based authentication and using https://github.com/sahat/satellizer for social media integration. $params = [ 'code' => $request->input('code'), 'client_id' => $request->input('clientId'), 'redirect_uri' => $request->input('redirectUri'), 'client_secret' => 'XXXXXXXXXXXXXXXXXXX' /*'client_secret' => Config::get('app.facebook_secret')*/ ]; // Step 1. Exchange authorization code for access token. $accessTokenResponse = $client->request(

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

邮差的信 提交于 2019-11-29 13:40:55
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??? I am also using guzzle, and its working for me, Try like this use GuzzleHttp; use GuzzleHttp\Subscriber

Guzzle ~6.0 multipart and form_params

自古美人都是妖i 提交于 2019-11-29 12:32:34
问题 I am trying to upload file and send post parameters at the same time like this: $response = $client->post('http://example.com/api', [ 'form_params' => [ 'name' => 'Example name', ], 'multipart' => [ [ 'name' => 'image', 'contents' => fopen('/path/to/image', 'r') ] ] ]); However my form_params fields are ignored and only the multipart fields are present in my post body. Can I send both at all with guzzle 6.0 ? 回答1: I ran into the same problem. You need to add your form_params to the multipart

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