简体   繁体   中英

How to get response from Guzzle Http in PHP

I'm building an application in Laravel 5.5 where I'm calling an api request to get response, I've following in my controller:

$client = new GuzzleHttp\Client();
$response = $client->request('GET', 'http://www.conxn.co.in/CoxnsvcA.svc/Login');
dd($response);

I'm able to get something like this:

测试

But while doing $response->getBody(); I'm unbale to get the response. when I do dd($response->getBody() I'm getting:

在此处输入图片说明

In postman it is showing something like this:

邮递员考试

Help me out with this.

Thanks.

This should work:

$client = new GuzzleHttp\Client();
$response = $client->request('GET','http://www.conxn.co.in/CoxnsvcA.svc/Login');

$response_body = json_decode($response->getBody());

This should work for you.

$client = new GuzzleHttp\Client();

$response = $client->request("GET", "http://www.googleapi.com", ['headers' => ['Accept' => 'application/json']]); 

$response_data = json_decode((string) $response->getBody(), true);

return collect($response_data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM