guzzle

laravel passport oauth function using curl or guzzle

本小妞迷上赌 提交于 2020-01-03 15:58:21
问题 I have this route in api route file Route::post('/user/register', 'HomeController@register'); and the register function is public function register(Request $request) { $user = User::create([ ... ]); return $this->getAccessToken($request); } public function getAccessToken(Request $request) { $url = url('/oauth/token'); $headers = ['Accept' => 'application/json']; $http = new Client; $response = $http->post($url, [ 'headers' => $headers, 'form_params' => [ 'grant_type' => 'password', 'client_id

MethodNotAllowedException Laravel Password Grant API

女生的网名这么多〃 提交于 2020-01-03 05:25:11
问题 I have recently developed a password grant API to be used by my client application. It is successfully generating access tokens for users after the client has been authorized. The problem I'm facing now is how to pass the access token back from client application to Laravel with each request? (as done by Headers in passport) I have gone through the laravel API Authentication by passport documentation. What I'm trying to do I have already tested the work flow of the API on postman. It was

400 Bad Request When Adding Member to MailChimp List

情到浓时终转凉″ 提交于 2020-01-02 19:20:10
问题 I am sending a POST request to the following resource and getting a 400. I understand what the error means, but still am unsure why I'm getting it when a GET request to the same resource works. /lists/{list_id}/members Here is a exerpt of the code: $client = new \GuzzleHttp\Client(); $response = $client->request('POST', // <-- Drop in a GET here and it works, other than it's not the behavior I need. env('MAILCHIMP_API_URL') . 'lists/' . env('MAILCHIMP_LIST_KEY') . '/members', [ 'auth' => [

How to handle Fatal error: cURL error 7: Failed to connect to xxxx port 443

流过昼夜 提交于 2020-01-02 05:04:09
问题 I have a script that connects to a third party API. It is and should be running on a non-stop loop 24/7 (I use a sleep at the end before restarting the loop). The problem is that sometimes the third party API gets ddosed or the connection simply drops with this error: Fatal error: Uncaught exception 'GuzzleHttp\Ring\Exception\ConnectException' with message 'cURL error 7: Failed to connect to xxx.com port 443 Is there any way to "break" on this fatal error to ensure the code is restarted and

Set proxy in Guzzle

被刻印的时光 ゝ 提交于 2020-01-02 02:02:54
问题 I have a problem with set proxy in guzzle that a blank page was shown while with curl everything works perfect. The code that I used in guzzle and curl came below. What is wrong with this code: Guzzle: use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; require_once "vendor/autoload.php"; try { $client = new Client(); $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org'); $response = $client->send($request, [ 'timeout' => 30, 'curl' => [ 'CURLOPT_PROXY' => '*.*.*.

Catching cURL errors from Guzzle

♀尐吖头ヾ 提交于 2020-01-01 12:16:30
问题 I have the following code that makes a Guzzle 4.1 request: $client = new \GuzzleHttp\Client(['defaults/headers/User-Agent' => $userAgentString]); $retry = 0; do { try { return $client->post($url, $options); } catch (\Exception $e) { echo $e->getMessage(); $retry++; continue; } } while ($retry < 3); It runs happily for quite a while but at random intervals it will sometimes have an issue with the cURL CA file which causes a fatal error due to an uncaught exception. I'm not sure I can do about

Catching cURL errors from Guzzle

社会主义新天地 提交于 2020-01-01 12:15:09
问题 I have the following code that makes a Guzzle 4.1 request: $client = new \GuzzleHttp\Client(['defaults/headers/User-Agent' => $userAgentString]); $retry = 0; do { try { return $client->post($url, $options); } catch (\Exception $e) { echo $e->getMessage(); $retry++; continue; } } while ($retry < 3); It runs happily for quite a while but at random intervals it will sometimes have an issue with the cURL CA file which causes a fatal error due to an uncaught exception. I'm not sure I can do about

Guzzle Cannot make GET request to the localhost (port: 80, 8000, 8080, etc )

时光怂恿深爱的人放手 提交于 2019-12-29 08:23:26
问题 Currently using Laravel 5.5 and Guzzle that comes together with the laravel installer. I am trying to make GET request (error occur with other HTTP requests as well) but don't seem work. This code does not work: public function callback(Request $request) { $code = $request->code; $client = new Client(['exceptions' => false]); try { $response = $client->request('GET', 'http://localhost/api/tests'); // $response = $http->request('POST', Config::get('app.url') . '/oauth/token', [ // 'form_params

Can Goutte/Guzzle be forced into UTF-8 mode?

时光毁灭记忆、已成空白 提交于 2019-12-29 04:53:41
问题 I'm scraping from a UTF-8 site, using Goutte, which internally uses Guzzle. The site declares a meta tag of UTF-8, thus: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> However, the content type header is thus: Content-Type: text/html and not: Content-Type: text/html; charset=utf-8 Thus, when I scrape, Goutte does not spot that it is UTF-8, and grabs data incorrectly. The remote site is not under my control, so I can't fix the problem there! Here's a set of scripts to

Guzzle 6 progress of download

元气小坏坏 提交于 2019-12-28 04:15:07
问题 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