Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Closed
Description
https://github.com/symfony/symfony-docs/blob/4.3/components/http_client.rst#psr-18
on full symfony project from symfony new --full project_name and after installing requirements
$psr17Factory = new Psr17Factory(); $psr18Client = new Psr18Client(); $url = 'https://symfony.com/versions.json'; $request = $psr17Factory->createRequest('GET', $url); $response = $psr18Client->sendRequest($request);// $response->getBody()->rewind(); // <--------------------- this line changed $content = json_decode($response->getBody()->getContents(), true); return new Response(\print_r($content, true));does not work, returns empty content
if I uncomment line (added by me, not present in docs):
$response->getBody()->rewind(); // <--------------------- this line changedit also works
and If i switch http driver to guzzle it also works:
<?phpdeclare(strict_types=1);namespace App\Controller;use Http\Adapter\Guzzle6\Client;use Http\Factory\Guzzle\RequestFactory;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;class TestController extends AbstractController{ /** * @Route("/test", name="app_test") */ public function index(): Response { $psr17Factory = new RequestFactory(); $psr18Client = Client::createWithConfig([]); $url = 'https://symfony.com/versions.json'; $request = $psr17Factory->createRequest('GET', $url); $response = $psr18Client->sendRequest($request); $content = json_decode($response->getBody()->getContents(), true); return new Response(\print_r($content, true)); }}so it is problem with symfony's http client,
most likely there is some issue with rewind of stream before returning contents