guzzle6

Proper way to send (POST) xml with guzzle 6

血红的双手。 提交于 2019-12-21 03:49:09
问题 I want to perform a post with guzzle sending an xml file. I did not find an example. What I 've done so far is : $xml2=simplexml_load_string($xml) or die("Error: Cannot create object"); use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $client = new Client(); // $request = new Request('POST', $uri, [ 'body'=>$xml]); $response = $client->send($request); // //$code = $response->getStatusCode(); // 200 //$reason = $response->getReasonPhrase(); // OK // echo $response->getBody(); No matter what

Guzzle get file and forward it

寵の児 提交于 2019-12-20 17:28:10
问题 I have a web-service that gets a file and returns it to the user (based on Symfony). Ever since I used curl to do this. I just found guzzlehttp and it seems great. However, I do not know how to do this with guzzle without saving the downloaded file (xml or txt) to a local file, read it from the file system a returning it to the user. I want to do this without saving to the file system. 回答1: public function streamAction() { $response = $client->request( 'GET', 'http://httpbin.org/stream-bytes

Guzzlehttp - How get the body of a response from Guzzle 6?

大憨熊 提交于 2019-12-17 02:42:17
问题 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 I try and do the same from PHP I get back a GuzzleHttp\Psr7\Response object, but can't seem to find the token anywhere inside it as I did with the Postman request. The relevant code looks like: $client

Guzzlehttp - How get the body of a response from Guzzle 6?

一个人想着一个人 提交于 2019-12-17 02:42:13
问题 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 I try and do the same from PHP I get back a GuzzleHttp\Psr7\Response object, but can't seem to find the token anywhere inside it as I did with the Postman request. The relevant code looks like: $client

Using PHP Guzzle HTTP 6 to send JSON with data that is already encoded

无人久伴 提交于 2019-12-14 04:17:59
问题 I am trying to send a POST request which contains a raw JSON string with the following header: Content-Type: application/json . From looking at the docs, I can see that I can do something like this... $data = ['x' => 1, 'y' => 2, 'z' => 3]; $client = new \GuzzleHttp\Client($guzzleConfig); $options = [ 'json' => $data, ]; $client->post('http://example.com', $options); My problem is that when I get to this point, $data has already been json_encode 'd. I have tried the following but it does not

Guzzle unable to bypass cURL error 35: SSL connect error

和自甴很熟 提交于 2019-12-13 16:19:55
问题 Using Guzzle 6 I am attempting to communicate with an Https endpoint that uses a self-signed certificate. I am instantiating my Client class as follows: $authClient = new Client([ 'base_uri' => config('app.auth_uri'), 'verify' => false ]); And attempting a request: $res = $this->authClient->request('POST', '/auth', [ 'form_params' => [ 'client_id' => 'XXXXXXXXXXXXXXX', 'username' => 'RSA', 'grant_type' => 'password' ] ]); Here is the error I get: cURL error 35: SSL connect error (see http:/

Guzzle digest auth not working

为君一笑 提交于 2019-12-12 03:25:21
问题 I'm trying to make an API that use digest as authentication, When I access API via curl command line using this command, it's work curl --digest --user website:website http://localhost/api/test/users but when running api client using Guzzle 6 php library using this code $handler = new GuzzleHttp\Handler\CurlHandler(); $stack = GuzzleHttp\HandlerStack::create($handler); // Wrap w/ middleware $client = new GuzzleHttp\Client(['base_uri' => 'http://localhost', 'handler' => $stack]); try {

guzzle 6.0 call to undefined method GuzzleHttp\Psr7\Response::xml()

三世轮回 提交于 2019-12-11 03:38:07
问题 I want to check the xml based responses from server, here is an example of the response format. <response> <code>success</code> </response> My existing code, use GuzzleHttp\Client; $client = new Client(); $response = $client->post('http://example.com/verify', [ 'form_params' => [ 'transID' => 1234, 'orderID' => 6789, 'token' => '0X45FJH79GD3332' ] ]); $xml = $response->xml(); dd($xml); However, when I make request to the server error occurs like below. Call to undefined method GuzzleHttp\Psr7

How do I profile Guzzle 6 requests?

可紊 提交于 2019-12-10 13:37:22
问题 I'm trying to profile the requests made to an API server from a PHP client using Guzzle (v 6). In the Guzzle 5.3 there is this complete and before event handling. class GuzzleProfiler implements SubscriberInterface { public function getEvents() { return [ 'before' => ['onBefore'], 'complete' => ['onComplete'] ]; } public function onBefore(BeforeEvent $event, $name) { start_profiling(); } public function onComplete(CompleteEvent $event, $name) { end_profiling(); } } But how do I do this in v6?

PHP Guzzle with basic auth and bearer token

谁说胖子不能爱 提交于 2019-12-10 13:05:16
问题 I'm trying to make a connection with infojobs-api, the documentation explian how to make it in this way: GET /api/1/application HTTP/1.1 Host: api.infojobs.net Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==,Bearer 07d18fac-77ea-461f-9bfe-a5e9d98deb3d (https://developer.infojobs.net/documentation/user-oauth2/index.xhtml) And this is my code: $basicauth = new Client(['base_uri' => 'https://api.infojobs.net']); $credentials = base64_encode(CLIENT_ID .':' . CLIENT_SECRET ) ; $newresponse =