File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,30 @@ dedicated web crawler or scraper such as `Goutte`_::
343
343
'.table-list-header-toggle a:nth-child(1)'
344
344
)->text());
345
345
346
+ Dealing with HTTP responses
347
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
348
+
349
+ When using the BrowserKit component, you may need to deal with responses of
350
+ the requests you made. To do so, you simply have to make a request, then call
351
+ the ``getResponse() `` method of the ``HttpBrowser `` object. This method
352
+ retrieves the last response the browser received::
353
+
354
+ $browser = new HttpBrowser(HttpClient::create());
355
+
356
+ $browser->request('GET', 'https://foo.com');
357
+ $response = $browser->getResponse();
358
+
359
+ If you're making requests that result in a JSON response, you
360
+ maye use the ``toArray() `` method of the response to directly get the
361
+ array representation of the JSON string you received. This avoids an
362
+ extra-call to ``json_decode() ``::
363
+
364
+ $browser = new HttpBrowser(HttpClient::create());
365
+
366
+ $browser->request('GET', 'https://api.foo.com');
367
+ $decodedResponse = $browser->getResponse()->toArray();
368
+ // $decodedResponse is an array of the decoded JSON.
369
+
346
370
Learn more
347
371
----------
348
372
You can’t perform that action at this time.
0 commit comments