guzzle / psr7

PSR-7 HTTP message library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$response->getBody()->getContents();获取到的值始终为空

RoRui opened this issue · comments

commented

PHP version: 8.1.4
sorry , i'm bad at english. so i don't know if I'm accurate.
Description

$pool = new Pool($client, $requests($urls), [
            'concurrency' => 2,
            'fulfilled' => function (Response $response, $index) {
                // this is delivered each successful response
               echo $response->getBody()->getContents();
            },
            'rejected' => function (RequestException $reason, $index) {
                // this is delivered each failed request
            },
        ]);

$response->getBody()->getContents();
The above method always returns a empty string value as ''.
I don't know if it's a bug.
I looked up the cause of the problem as follows:
Utils.php:416, GuzzleHttp\Psr7\Utils::tryGetContents()
Stream.php:103, GuzzleHttp\Psr7\Stream->getContents()

       try {
            /** @var string|false $contents */
           //The bug was fixed after I modified the following code
          //$contents = stream_get_contents($stream)
            $contents = stream_get_contents($stream,-1,0);

            if ($contents === false) {
                $ex = new \RuntimeException('Unable to read stream contents');
            }
        } catch (\Throwable $e) {
            $ex = new \RuntimeException(sprintf(
                'Unable to read stream contents: %s',
                $e->getMessage()
            ), 0, $e);
        }

Sorry, we ca only process issues written in English.