【发布时间】:2019-08-27 17:49:08
【问题描述】:
我使用 Guzzle 来使用来自外部 WS 的数据。但是,我在获取数据时遇到了问题。
$body = $response->getBody()->getContents();
使用上面的代码,我得到一个空响应。
如果我将正文转换为流并使用此代码:
$body = $response->getBody();
$stream = Psr7\stream_for($body);
$results = $stream->read(1024);
我得到数据,但这些数据被截断(1024 个字符)。
为什么第一个代码没有返回任何数据?有没有办法为'->read'函数添加“无限”选项?
我测试了很多解决方案,但都没有成功:
$response->getBody()->rewind();
$response->getBody()->__toString();
(string) $response->getBody()...
感谢您的帮助。
【问题讨论】: