PHP Guzzle: Empty body response

假如想象 提交于 2019-12-23 09:36:55

问题


I just started experimenting with guzzle but i am getting an empty string on the response body

    $client = new Client([
      'base_uri' => 'http://httpbin.org',
      'timeout'  => 2.0,
   ]);
   $response = $client->request('GET', '', ['debug' => true]);
   var_dump($response->getBody()->getContents());

And the response i am getting is:

* About to connect() to httpbin.org port 80 (#0)
*   Trying 23.22.14.18...
* Connected to httpbin.org (23.22.14.18) port 80 (#0)
> GET / HTTP/1.1
User-Agent: GuzzleHttp/6.2.0 curl/7.29.0 PHP/5.5.34
Host: httpbin.org

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 06 Jun 2016 06:48:13 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 12150
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

* Connection #0 to host httpbin.org left intact
string(0) ""

As you can see the body is "" but the Content-Length is correct.


回答1:


There is a bad commit on the master branch of guzzlehttp/psr7. If you lock the version in your composer.json file, everything should be working as expected.

"guzzlehttp/guzzle": "6.2",
"guzzlehttp/psr7": "1.3"


来源:https://stackoverflow.com/questions/37651164/php-guzzle-empty-body-response

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!