本文介绍了PHP狂饮:空荡荡的身体反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始尝试吃一些食肉,但是我在响应主体上得到了一个空字符串

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());

我得到的答复是:

* 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) ""

如您所见,正文为",但Content-Length是正确的.

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

推荐答案

guzzlehttp/psr7的master分支上的提交错误.如果您将版本锁定在您的composer.json文件中,则所有内容都应可以正常工作.

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"

这篇关于PHP狂饮:空荡荡的身体反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:53