guzzle

How can I require composer autoloader in the laravel?

微笑、不失礼 提交于 2019-12-02 03:46:02
问题 I want to install guzzle https://github.com/guzzle/guzzle I read the reference, but I'm confused this section : From that tutorial, asking for require composer autoloader. So seems needed to add require 'vendor/autoload.php'; Where I add the script? I using laravel 5.6 回答1: You don't have to do anything if you are going to install guzzle in Laravel. The example above is for core php actually. Laravel will automatically do it for you. Just run composer require guzzlehttp/guzzle in your

Why is my Authorization Header giving me a 401 in Guzzle?

家住魔仙堡 提交于 2019-12-02 01:48:56
问题 I am getting a 401 on Guzzle 4.2 and the same setup works on Postman. Code below. // Create a client with a base URL $client = new GuzzleHttp\Client(['base_url' => 'cloud.feedly.com/v3/streams/contents?streamId=user/user-id/category/global.all&count=1']); // Send a request to https://github.com/notifications $response = $client->get(); //Auth $response->addHeader('Authorization', "auth-code"); //send $r = $response->send(); dd($r->json()); The error is: GuzzleHttp \ Exception \

How can I require composer autoloader in the laravel?

前提是你 提交于 2019-12-02 00:16:16
I want to install guzzle https://github.com/guzzle/guzzle I read the reference, but I'm confused this section : From that tutorial, asking for require composer autoloader. So seems needed to add require 'vendor/autoload.php'; Where I add the script? I using laravel 5.6 You don't have to do anything if you are going to install guzzle in Laravel. The example above is for core php actually. Laravel will automatically do it for you. Just run composer require guzzlehttp/guzzle in your terminal. (of course in the directory where your laravel project actually is.) And add use GuzzleHttp\Client; at

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" =>

Why is my Authorization Header giving me a 401 in Guzzle?

大兔子大兔子 提交于 2019-12-01 22:50:22
I am getting a 401 on Guzzle 4.2 and the same setup works on Postman. Code below. // Create a client with a base URL $client = new GuzzleHttp\Client(['base_url' => 'cloud.feedly.com/v3/streams/contents?streamId=user/user-id/category/global.all&count=1']); // Send a request to https://github.com/notifications $response = $client->get(); //Auth $response->addHeader('Authorization', "auth-code"); //send $r = $response->send(); dd($r->json()); The error is: GuzzleHttp \ Exception \ ClientException (401) Client error response [url] cloud.feedly.com/v3/streams/contents?streamId=user/user-id/global

关于重复发布文章的改进

♀尐吖头ヾ 提交于 2019-12-01 22:32:10
同步文章使用了Linux系统的Cron服务,通过命令 curl 请求服务器url 执行更新,将发布时间 小于或等于 当前时间的文章发布到osc博客中去。 实际操作发现存在同一篇文章多次重复同步的问题,推测是在网络不好的情况下,文章发布会超过一分钟,甚至更多,由于定时任务是每分钟执行一次,这时就可能产生多个crond并行, 其实最根本原因是cron使用的curl默认情况没有设定超时时间,会一直等待请求响应,当网络突然好转时,会在一瞬间将多篇文章更新上去。 目前的做法是限制curl的最大执行时间为45秒,理论上只要小于一分钟就可以了,只要不同时出现多个crond进程就行了。 然后对同步的url的action进行了加锁处理,使用的库是 texthtml/php-lock ,简单的文件锁就够用了,保证一篇文章同一时间只有一个请求同步的操作,同时对guzzle设置了timeout参数,时间限制在40秒。 来源: oschina 链接: https://my.oschina.net/falcon10086/blog/3135828

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

Building query string programmatically in Guzzle?

旧城冷巷雨未停 提交于 2019-12-01 14:07:33
问题 In my PHP Guzzle client code, I have something like $c = new Client('http://test.com/api/1.0/function'); $request = $c->get('?f=4&l=2&p=3&u=5'); but instead I want to have something like: $request->set('f', 4); $request->set('l', 2); $request->set('p', 3); $request->set('u', 5); Is it possible in Guzzle? From the documentation and random googling it would seem it is, but I can't find exactly how. 回答1: You can: $c = new Client('http://test.com/api/1.0/function'); $request = $c->get(); $q =

...cURL error 60: SSL certificate problem: unable to get local issuer certificate...

时光毁灭记忆、已成空白 提交于 2019-12-01 10:09:23
问题描述: 在做PHP爬虫的时候, 安装了 guzzle 和 dom-crawler 之后, 调用的时候出现问题, 如下 报错内容: Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in E:\project\my_test\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:186 Stack trace: #0 E:\project\my_test\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(149): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 E:\project\my_test\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory