Skip to content

Commit a79e874

Browse files
committed
minor #16950 [BrowserKit] Add response management to BrowserKit documentation (with toArray) (alexandre-daubois)
This PR was merged into the 6.1 branch. Discussion ---------- [BrowserKit] Add response management to BrowserKit documentation (with toArray) Closes #16580 Commits ------- ce6ebfb [BrowserKit] Add response management to BrowserKit documentation
2 parents 5624d2d + ce6ebfb commit a79e874

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/browser_kit.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,15 @@ dedicated web crawler or scraper such as `Goutte`_::
343343
'.table-list-header-toggle a:nth-child(1)'
344344
)->text());
345345

346+
<<<<<<< HEAD
346347
.. tip::
347348

348349
You can also use HTTP client options like ``ciphers``, ``auth_basic`` and
349350
``query``. They have to be passed as the default options argument to the
350351
client which is used by the HTTP browser.
351352

353+
=======
354+
>>>>>>> 4f790b856 ([BrowserKit] Add response management to BrowserKit documentation)
352355
Dealing with HTTP responses
353356
~~~~~~~~~~~~~~~~~~~~~~~~~~~
354357

@@ -361,6 +364,20 @@ the requests you made. To do so, call the ``getResponse()`` method of the
361364
$browser->request('GET', 'https://foo.com');
362365
$response = $browser->getResponse();
363366

367+
If you're making requests that result in a JSON response, you may use the
368+
``toArray()`` method to turn the JSON document into a PHP array without having
369+
to call ``json_decode()`` explicitly::
370+
371+
$browser = new HttpBrowser(HttpClient::create());
372+
373+
$browser->request('GET', 'https://api.foo.com');
374+
$response = $browser->getResponse()->toArray();
375+
// $response is a PHP array of the decoded JSON contents
376+
377+
.. versionadded:: 6.1
378+
379+
The ``toArray()`` method was introduced in Symfony 6.1.
380+
364381
Learn more
365382
----------
366383

0 commit comments

Comments
 (0)