From ce6ebfb3d6caf6bf2ed21a372de3069215a77940 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Thu, 7 Jul 2022 16:47:42 +0200 Subject: [PATCH] [BrowserKit] Add response management to BrowserKit documentation --- components/browser_kit.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/browser_kit.rst b/components/browser_kit.rst index a2afe27c0bc..488bc44d385 100644 --- a/components/browser_kit.rst +++ b/components/browser_kit.rst @@ -343,12 +343,15 @@ dedicated web crawler or scraper such as `Goutte`_:: '.table-list-header-toggle a:nth-child(1)' )->text()); +<<<<<<< HEAD .. tip:: You can also use HTTP client options like ``ciphers``, ``auth_basic`` and ``query``. They have to be passed as the default options argument to the client which is used by the HTTP browser. +======= +>>>>>>> 4f790b856 ([BrowserKit] Add response management to BrowserKit documentation) Dealing with HTTP responses ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -361,6 +364,20 @@ the requests you made. To do so, call the ``getResponse()`` method of the $browser->request('GET', 'https://foo.com'); $response = $browser->getResponse(); +If you're making requests that result in a JSON response, you may use the +``toArray()`` method to turn the JSON document into a PHP array without having +to call ``json_decode()`` explicitly:: + + $browser = new HttpBrowser(HttpClient::create()); + + $browser->request('GET', 'https://api.foo.com'); + $response = $browser->getResponse()->toArray(); + // $response is a PHP array of the decoded JSON contents + +.. versionadded:: 6.1 + + The ``toArray()`` method was introduced in Symfony 6.1. + Learn more ----------