FAQ Database Discussion Community


Testing a class in phpspec involving Guzzle

unit-testing,guzzle,phpspec
I'm trying to build a class that queries an external API. Each method that corresponds to an endpoint makes a call to a 'master call' method responsible for actually sending a request to the API. For example: // $this->http is Guzzlehttp\Client 5.3 public function call($httpMethod, $endpoint, array $parameters = [])...

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

php,rest,guzzle
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...

Takes Guzzle's client as constructor argument

php,guzzle
I create a Client class which implement interface. I need takes Guzzle's client as constructor argument, but i can't do that. <?php namespace Payum\Core\Bridge\Psr\Http; use GuzzleHttp\Client; use Psr\Http\Message\ResponseInterface; class Client implements ClientInterface { $client = new \GuzzleHttp\Client(); // there is error 'Unexpected' public function __construct($client) { } public function responeInterface()...

base_uri not being based from guzzle client instantiation

guzzle,lumen
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',...

Getting bytes/sec on a Guzzle transfer

guzzle
Is it possible to calculate the bytes/sec on GET requests created by Guzzle 4 or 5? If so, how is this done?...

Guzzle ~6.0 multipart and form_params

php,curl,guzzle
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...

Can't install guzzlehttp for Laravel

laravel-5,guzzle
I am using PHP 5.4 and I have Laravel 5.1 for my development. When I try to install guzzlehttp through composer for my Laravel I get error that your PHP 5.4 doesn't specify the requirements. i tried to install it by lowering the version like composer require "guzzlehttp/guzzle": "5.0" but...

Guzzle without composer

php,composer-php,guzzle
I need to use sproutvideo php lib that requires Guzzle Guzzle needs composer to install and not sure if is needed to run, since in some file i found require 'vendor/autoload.php'; i never used composer and i'm on shared hosting, where i can't install it i download Guzzle from github...

Guzzle pool in PHP application

php,promise,guzzle,reactphp
I am trying to use Guzzle pool in PHP. But I am having difficulty in dealing with ASYNC request. Below is the code snippet. $client = new \GuzzleHttp\Client(); function test() { $client = new \GuzzleHttp\Client(); $request = $client->createRequest('GET', 'http://l/?n=0', ['future' => true]); $client->send($request)->then(function ($response) { //echo 'Got a response! '...

guzzle ver 6 post method is not woking

php,guzzle
is working in postman (raw format data with with application/json type) with guzzle6 url-http://vm.xxxxx.com/v1/hirejob/ { "company_name":" company_name", "last_date_apply":"06/12/2015", "rid":"89498" } so am getting response 201 created but in guzzle $client = new Client(); $data = array(); $data['company_name'] = "company_name"; $data['last_date_apply'] = "06/12/2015"; $data['rid'] = "89498"; $url='http://vm.xxxxx.com/v1/hirejob/'; $data=json_encode($data); try { $request...

Yii console app - Class 'Guzzle\Http\Client' not found

web-applications,yii,console-application,guzzle
My configs: /trunk/common/extensions/Api/Api.php /trunk/vendor/guzzle webapp config: /trunk/members/config/main.php ... 'components' => array( 'api' => array( 'class' => 'common.extensions.Api.Api' ) ... ) ... console config: /trunk/console/config/main.php ... 'components' => array( 'api' => array( 'class' => 'common.extensions.Api.Api' ) ... ) ... Client.php namespace Guzzle\Http; Guzzle was installed via composer. When I run the...

GuzzlePHP Request Query String

php,amazon,guzzle
I'm working on an application using Amazon's CloudDrive SDK. When requesting a list of folders or files, you can send filters in the query string, but the values of each filter needs to have special characters escaped (included spaces, much like a Linux command line argument). I'm not entirely sure...

Doing “curl -u” with Guzzle

php,guzzle
I'm working with a service that requires me to call it via: curl -u username:password -X POST "http://www.theirurl.com" I'd like to use Guzzle rather than do a raw CURL, however. Is there a way to have Guzzle pass the -u parameter? I tried User-Agent, but that's not correct....

Laravel - Guzzle not returning any data even though URL is correct

php,laravel,laravel-4,laravel-5,guzzle
I am trying to return the JSON data from a third party API - http://postcodes.io/. I currently have in my controller: $client = new Client(); $request = $client ->get('https://api.postcodes.io/postcodes/'.Input::get('postcode')); $statusCode = $request->getStatusCode(); if ($statusCode >= 200 && $statusCode < 300) { $json = Response::json($request); // Returns JSON decoded array of...

Resource of type unknown when passed to Guzzle's createRequest method [on hold]

php,guzzle
When I pass a resource reference in the body element of the $option argument for createRequest, Guzzle 5.3.0 transforms the resource type stream into unknown. This makes the resource unusable and causes an exception from within Guzzle. e.g. $fp = fopen('path/to/a/file.txt'); $request = $client->createRequest('POST', $someUrl, ['body' => $fp]); Just before...

How to get the public objects

php,object,guzzle,rackspace-cloud,rackspace
I'm working on PHP with Rackspace API, this is what I have used here: $file->setContent(fopen('sites/default/files/rackspace/' . $end_element, 'r+')); $cdnUrl = $file->getPublicUrl(); print_r($cdnUrl); And its returning me the below mentioned structure. Guzzle\Http\Url Object ( [scheme:protected] => http [host:protected] => something.r2.cf3.rackcdn.com [port:protected] => [username:protected] => [password:protected] => [path:protected] => /something-abc.jpg [fragment:protected] =>...

Unable to find wrapper when testing Guzzle call with PHPUnit

php,codeigniter,phpunit,guzzle
I am writing a unit test for an API that I am developing. The API is written in the Codeigniter framework, that calls another API using Guzzle. The test I am writing verifies that the API call returns the correct response. The Test.php file contains the following code require '/application/libraries/apiWrappers/Breathehr.php';...

Post request with GuzzleHttp

http,post,guzzle
I'm trying to make a post request like this example: $response = $guzzle->post('http://www.website.com/abc.asp?2014:62/9/931/99999', [ 'body' => [ 'f' => 'json' ] ]); But when i run that code i get an 505 error because the url was literally encoded after ?....

Guzzlehttp - how do I work with / get my expected response?

php,response,guzzle
I'm trying to write a wrapper around an api my company is developing. It's restful, and using Postman I can send a post request to an endpoint like http://subdomain.dev.myapi.com/api/v1/auth/ with a username and password as POST data and I am given back a token. All works as expected. Now, when...

guzzlehttp/guzzle sends HTTP request before ->send()

php,rest,composer-php,guzzle,postmates
I'm trying to use Guzzle to consume a RESTful API. Reading the Guzzle documentation, I call methods like get and post to configure a request, then send to actually run an HTTP request. $request = $client->post('http://httpbin.org/post', array(), array( 'custom_field' => 'my custom value', 'file_field' => '@/path/to/file.xml' )); $response = $request->send();...

Bigcommerce API - Creating Webhooks - Invalid Header

php,bigcommerce,webhooks,guzzle
I'm making small steps into this project I am working on. Now creating and registering a webhook. I'm getting the below response: 400 - Invalid Header I have tried the following code: // Send a request to register a web hook $http2 = new Client('https://api.bigcommerce.com', array( 'request.options' => array( 'exceptions'...

GuzzleHttp \ Exception \ RequestException cURL error 52: Empty reply from server

php,laravel,laravel-4,mandrill,guzzle
Trying to send email with Laravel using Mandrill. I've set up a test API on Mandrill and have put the API key into the services.php config array, and set the driver to 'mandrill'. Here's how I'm sending the email: $data = array( 'activation_code' => $user->activation_code ); Mail::send('emails.auth.activate', $data, function($message) use...

How to create own RequestException in Guzzle

guzzle
My code if ($title === 'server-400') { throw new \GuzzleHttp\Exception\RequestException(" Missing parameter "); } but when it run it show message like this: Argument 2 passed to GuzzleHttp\Exception\RequestException::__construct() must be an instance of GuzzleHttp\Mess age\RequestInterface, none given It required 2 parameters which are $message and $request, I do not know...

How to access Guzzle QueryString parameters in Ratchet WebSockets?

php,guzzle,ratchet
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...

How to pass parameter to an api post method?

symfony2,guzzle
I am using guzzle to call my api, and in my url contain one dynamic id http://myapiurl.com/products/{productId}/phone $client = new Client([ 'base_url' => [ 'http://myapiurl.com/product/{productId}/phone', ['productId' => $productId] ] ]); $repsonse = $client->post( '/', [ json' => [ 'title' => $title, 'description' => $description, ], ] ); But it generate...

Guzzle error 500

php,laravel-5,guzzle
so i have a CURL request that looks like this (and it works): curl -X GET -H "Authorization: Token 1234567890" http://api.website.com tried translating it into Laravel Guzzle into something like this: $client = new \GuzzleHttp\Client(['base_uri' => 'http://api.website.com']); $headers = ['Authorization' => 'Token 1234567890']; $response = $client->get($query_string, $headers); return $response; but...

PHP Guzzle 5: Cannot handle URL with PORT number in it

php,url,curl,port,guzzle
I am using the latest version of guzzle. (from composer.json) "guzzlehttp/guzzle": "~5" (from composer.lock) "name": "guzzlehttp/guzzle", "version": "5.2.0", When I attempt to request (GET or POST) with a URL that contains a PORT number: $response = $client->get('http://www.hostdnshere.com:8888', array()); I get the following error: string(68) "cURL error 7: Failed to connect...

Adding Guzzle For Mailgun in Laravel 5

php,laravel-5,guzzle,mailgun
I want to use the Mailgun service in Laravel 5. This requires Guzzle 5 to be installed. I've added the following to composer.json, and installed it: "guzzlehttp/guzzle": "~5.0" However, my app is giving me this error: FatalErrorException in MailgunTransport.php line 121: Class 'GuzzleHttp\Client' not found I've ran composer dump-autoload. What...

What is the purpose of tag “guzzle.client” in guzzle client bundle in symfony2 ?

symfony2,bundle,guzzle
I am using the guzzle client bundle in a symfony2 project and I checked the configuration provided here : https://github.com/misd-service-development/guzzle-bundle/blob/master/Resources/doc/clients.md // MyBundle/Resources/config/services.xml <service id="example.client" class="%guzzle.client.class%"> <tag name="guzzle.client"/> <argument>http://api.example.com/</argument> </service> It would be awesome if somebody can explain why we need the tag ....

How to set CURLOPT_PROXY in Guzzle right way?

php,curl,guzzle
I am trying to set CURLOPT_PROXY but it doesn't work. Curl is enabled. If I do this by "raw" curl request - everything works.. So? What could be the solution? $client = new GuzzleHttp\Client(); $res = $client->get('http://www.ipmango.com/api/myip', [ 'config' => [ 'curl' => [ 'CURLOPT_PROXY' => '194.135.220.18:8081', ], ] ]);...

how to download image in Goutte

php,web-crawler,guzzle,goutte
I want to download an image in this page. The image source ishttp://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg. I try to download it use this: $client = new Goutte\Client (); $client->getClient->get($img_url, array('save_to' => $img_url_save_name)); But I failed, then I realize if I directly accesshttp://i2.pixiv.net/c/600x600/img-master/img/2015/01/19/12/17/13/48258889_p0_master1200.jpg, I are denied by CDN nginx server. I have to access...