guzzle

How can I upload files to GoogleDrive in “multipart” type by using Guzzle?

你离开我真会死。 提交于 2020-04-17 07:18:07
问题 With the help of @Tanaike(see here), I can successfully upload files to GoogleDrive by using php-curl, here is my code by using php-curl: function uploadByCurl($uploadFilePath, $accessToken){ $ch = curl_init(); $boundary = md5(mt_rand() . microtime()); //MetaData $params = json_encode([ 'name' => basename($uploadFilePath), 'description' => 'This is a test', ]); $fileContent = file_get_contents($uploadFilePath); $dataToUpload = "--{$boundary}\r\n"; $dataToUpload .= "Content-Type: application

[PHP] 使用guzzle发送异步的HTTP请求

假装没事ソ 提交于 2020-04-10 12:00:35
PHP中请求一个HTTP服务,一般都是阻塞的, 如果有多个HTTP请求 , 需要串行的执行 , 一个接一个的请求 , 可以使用guzzle php这个类库来异步的同时发送多个HTTP请求 . 结果的响应时间取决于最长的那个请求的响应时间 测试代码如下: $client = new \GuzzleHttp\Client(); // 发送一个异步请求 $request = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com' ); $request2 = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com/laruence' ); $request3 = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com/about' ); $promise = $client ->sendAsync( $request )->then( function ( $response ) { echo 111 ; }); $promise = $client ->sendAsync( $request2 )->then( function ( $response ) use ( $client ,

[PHP] 使用guzzle发送异步的HTTP请求

风流意气都作罢 提交于 2020-04-10 11:39:04
PHP中请求一个HTTP服务,一般都是阻塞的, 如果有多个HTTP请求 , 需要串行的执行 , 一个接一个的请求 , 可以使用guzzle php这个类库来异步的同时发送多个HTTP请求 . 结果的响应时间取决于最长的那个请求的响应时间 测试代码如下: $client = new \GuzzleHttp\Client(); // 发送一个异步请求 $request = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com' ); $request2 = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com/laruence' ); $request3 = new \GuzzleHttp\Psr7\Request('GET', 'http://www.sopans.com/about' ); $promise = $client ->sendAsync( $request )->then( function ( $response ) { echo 111 ; }); $promise = $client ->sendAsync( $request2 )->then( function ( $response ) use ( $client ,

利用Guzzle采集数据

戏子无情 提交于 2020-02-27 07:23:48
在这里我想说一下,本章旨在学习,无任何越权操作!都是在thinkphp5的环境下,本地环境localhost 通过composer安装完成Guzzle之后,引入 use GuzzleHttp\Client ; $client = new Client(); $url = 'http://www.xxxxxxx.cn/api/getData?params=www.xxxxx.cn' ; //在这一步,headers里面的参数,类似于伪造访问ip(不知道这样说对不对),相关配置详见Guzzle文档 https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html#headers $response = $client ->request( 'GET' , $url , [ 'headers' => [ 'x-forwarded-for' => 'xxx.xxx.xxx.xxx' ] ])->getBody()->getContents(); $data = json_decode ( $response , true ); dump( $data ); exit ; $this ->assign( 'content' , $data ); return $this -> view ->fetch( 'other' );

base_uri not being based from guzzle client instantiation

巧了我就是萌 提交于 2020-01-31 04:32:25
问题 I'm using lumen trying to set up simple api requests via guzzle. The problem is the base_uri parameter doesn't appear to be passed correctly on the initial new Client() . Simplified example: use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'https://siteurl.com/api/v2' ]); Then calling the api via get $res = $client->get('orders', [ 'query' => [ 'status' => 'completed' ] ]); does not work. I've been careful not to use absolute urls like /orders . If I bypass base_uri entirely and

Http guzzle request with no response

只谈情不闲聊 提交于 2020-01-25 07:15:46
问题 In my Lumen project, I needed to use the Guzzle client to send requests from the server side to create acces tokens and provide them to the correctly authentified users. The problem is that whenener I send a guzzlehttp request I get no response, using Postmen to send them and request stops just because of the time out. I tried simple example in the web.php file: <?php use GuzzleHttp\Client; $app->get('/', function () use ($app) { //return $app->version(); $http= new Client(); return json

Storing parts of API data to database

泄露秘密 提交于 2020-01-24 21:37:05
问题 Goal: I want to retrieve all the upcoming soccer matches for the upcoming week from a RESTful API. Once I get this data I would like to store the result in my database. What I want to store: 'id', 'homeTeam', 'awayTeam', 'utcDate' . I want to do this for every match, so all the arrays in 'matches' How my API result looks: array:4 [▼ "count" => 10 "filters" => array:1 [▶] "competition" => array:6 [▶] "matches" => array:10 [▼ 0 => array:12 [▼ "id" => 233107 "season" => array:4 [▶] "utcDate" =>

Guzzle Async Multiple Promises

会有一股神秘感。 提交于 2020-01-16 19:41:45
问题 So I'm trying to use guzzle for a couple of concurrent requests. I've seen several examples online and this is what I came up with, but can't seem to get it to work. No errors, no warnings, nothing. I've tried logging inside each promise but nothing happens. And I know for sure that nothing is happening because nothing is getting inserted in the DB. Any ideas what I'm missing? (I'm yielding each request with its respective then because at the end of each promise, the DB operations are

How to access Guzzle QueryString parameters in Ratchet WebSockets?

£可爱£侵袭症+ 提交于 2020-01-16 03:38:05
问题 Hi I am using radchet websocket. I am getting trouble to get my data from an object variable. Please check my code: var conn = new WebSocket('ws://localhost:8080?user_id=10&receiver_id=20'); $querystring = $conn->WebSocket->request->getQuery(); print_r($querystring); Output: Guzzle\Http\QueryString Object ( [fieldSeparator:protected] => & [valueSeparator:protected] => = [urlEncode:protected] => RFC 3986 [aggregator:protected] => [data:protected] => Array ( [user_id] => 10 [receiver_id] => 20

Disable urlencode in POST request in Guzzle

 ̄綄美尐妖づ 提交于 2020-01-15 11:14:32
问题 I am trying to post some data and Guzzle automatically urlencode() all post values. I want to disable it because its acting weird (There is a problem with the Enter character). I searched the documentation and found a reference about this $query->useUrlEncoding(false); but its about GET requests. Also documentation says : "URL encoding can be disabled by passing false, enabled by passing true, set to use RFC 1738 by passing Query::FORM_URLENCODED (internally uses PHP's urlencode function), or