guzzle

How do I send parameters for a PUT request in Guzzle 5?

老子叫甜甜 提交于 2019-12-04 20:08:26
问题 I have this code for sending parameters for a POST request, which works: $client = new GuzzleHttp\Client(); $request = $client->createRequest('POST', 'http://example.com/test.php'); $body = $request->getBody(); $request->getBody()->replaceFields([ 'name' => 'Bob' ]); However, when I change POST to PUT, I get this error: Call to a member function replaceFields() on a non-object This is because getBody is returning null. Is it actually correct to send PUT parameters in the body? Or should I do

Installation Guzzle in Laravel 5

核能气质少年 提交于 2019-12-04 16:46:58
问题 how to Install Guzzle into Laravel 5? I'm using laravel for my project, but I need library like guzzle to made me easy using curl in laravel. Any Body can help? 回答1: Open a terminal, change into your laravel projects root dir and type composer require guzzlehttp/guzzle Alternatively, you can add "guzzlehttp/guzzle":"*" to your composer.json file's require section and run composer update. 回答2: Via composer, cd into your laravel's project root directory, then composer require guzzlehttp/guzzle

Curl error 7 on vagrant using guzzle

一世执手 提交于 2019-12-04 15:02:57
I've get an Curl error 7: Failed to connect to site1.local port 8000: Connection refused , when i call it from another local site (site2.local). Both sites run on the same Vagrant box. When i replace the url to an url of an external site (eg. google.com), there is no problem in connecting. Why does vagrant refuse a call from his own? I searched the problem, but couldn't find any solution to this. Is there a way to call to another site on the same server using curl? edit: Vagrantfile: Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| Homestead.configure(config, YAML::load(File.read(path +

Sage One API - unsupported_grant_type

落花浮王杯 提交于 2019-12-04 12:37:35
I am trying to obtain an access token for Sage One API by following the docs using Guzzle (v6) / Laravel 5.2 (Laravel's involvement is irrelevant for this question), it is stuck at the "request access token" stage. The error Client error: `POST https://api.sageone.com/oauth2/token` resulted in a `400 Bad Request` response: {"error":"unsupported_grant_type"} The offending code $client = new Client([ 'base_uri'=>'https://api.sageone.com', 'headers' => ['content_type' => 'application/x-www-form-urlencoded'] ]); $data = [ 'client_id' => getenv('SAGE_CLIENT'), 'client_secret' => getenv('SAGE_SECRET

Catching cURL errors from Guzzle

自作多情 提交于 2019-12-04 10:21:32
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 this because I already have it in a try catch block. Here is the error that takes down my Laravel

Using Guzzle promises asyncronously

半世苍凉 提交于 2019-12-04 07:06:52
I am attempting to use guzzle promises in order to make some http calls, to illustrate what I have, I have made this simple example where a fake http request would take 5 seconds: $then = microtime(true); $promise = new Promise( function() use (&$promise) { //Make a request to an http server $httpResponse = 200; sleep(5); $promise->resolve($httpResponse); }); $promise2 = new Promise( function() use (&$promise2) { //Make a request to an http server $httpResponse = 200; sleep(5); $promise2->resolve($httpResponse); }); echo 'PROMISE_1 ' . $promise->wait(); echo 'PROMISE_2 ' . $promise2->wait();

Guzzle send() method causes cURL error 35 Too many open files

大兔子大兔子 提交于 2019-12-04 06:35:34
问题 Trying to execute the following code with Guzzle 5. $client = new GuzzleClient(['defaults/headers/User-Agent' => static::$userAgentString]); $request = $client->createRequest(static::$serviceRequestMethod, $url, $options); // Create signing request. $signature = new Signature\Signature($this->accessKey, $this->secretKey); $options = array_merge_recursive($options, ['query' => ['Signature' => $signature->signString($hash)]]); $request = $client->createRequest(static::$serviceRequestMethod,

Translate cURL request to Guzzle

自古美人都是妖i 提交于 2019-12-04 06:24:42
I am trying to use Guzzle instead of directly using cURL to achieve and HTTP request. How do I make this same type of request but with Guzzle? Or should I just stick to cURL? $ch = curl_init(); // Set the URL curl_setopt($ch, CURLOPT_URL, $url); // don't verify SSL certificate curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Return the contents of the response as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Follow redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Set up authentication curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "

Laravel - Guzzle Request / cURL error 6: Could not resolve host

可紊 提交于 2019-12-04 04:24:36
问题 I try to make an API Request to the Github API just for testing. I installed the latest Guzzle Version ( "guzzle/guzzle": "^3.9" ) on my Laravel 5.1 APP. In my routes.php i have the following Code: Route::get('guzzle/{username}', function($username) { $client = new Client([ 'base_uri' => 'https://api.github.com/users/', ]); $response = $client->get("/users/$username"); dd($response); }); If i now visit the URL domain.dev/github/kayyyy i get the Error cURL error 6: Could not resolve host:

How to get past login screen on Guzzle call

纵然是瞬间 提交于 2019-12-03 18:03:56
问题 I have to send information to an external website using cURL. I set up Guzzle on my Laravel application. I have the basics set up, but according to the documentation of the website, there is an action that's required for the username and password. How can I pass the 'action' along with the credentials needed to log in and get access? The website states: curl [-k] –dump-header <header_file> -F “action=login” -F “username=<username>” -F “password=<password>” https://<website_URL> My controller: