@@ -8,6 +8,12 @@ The BrowserKit Component
8
8
The BrowserKit component simulates the behavior of a web browser, allowing
9
9
you to make requests, click on links and submit forms programmatically.
10
10
11
+ .. note ::
12
+
13
+ The BrowserKit component can only make internal requests to your application.
14
+ If you need to make requests to external sites and applications, consider
15
+ using `Goutte `_, a simple web scraper based on Symfony Components.
16
+
11
17
Installation
12
18
------------
13
19
60
66
use Acme\Client;
61
67
62
68
$client = new Client();
63
- $crawler = $client->request('GET', 'http://symfony.com ');
69
+ $crawler = $client->request('GET', '/ ');
64
70
65
71
The value returned by the ``request() `` method is an instance of the
66
72
:class: `Symfony\\ Component\\ DomCrawler\\ Crawler ` class, provided by the
@@ -78,7 +84,7 @@ performs the needed HTTP GET request to simulate the link click::
78
84
use Acme\Client;
79
85
80
86
$client = new Client();
81
- $crawler = $client->request('GET', 'http://symfony.com ');
87
+ $crawler = $client->request('GET', '/product/123 ');
82
88
$link = $crawler->selectLink('Go elsewhere...')->link();
83
89
$client->click($link);
84
90
@@ -120,7 +126,7 @@ retrieve any cookie while making requests with the client::
120
126
121
127
// Make a request
122
128
$client = new Client();
123
- $crawler = $client->request('GET', 'http://symfony.com ');
129
+ $crawler = $client->request('GET', '/ ');
124
130
125
131
// Get the cookie Jar
126
132
$cookieJar = $client->getCookieJar();
@@ -152,7 +158,7 @@ Looping Through Cookies
152
158
153
159
// Make a request
154
160
$client = new Client();
155
- $crawler = $client->request('GET', 'http://symfony.com ');
161
+ $crawler = $client->request('GET', '/ ');
156
162
157
163
// Get the cookie Jar
158
164
$cookieJar = $client->getCookieJar();
@@ -198,9 +204,8 @@ history::
198
204
199
205
use Acme\Client;
200
206
201
- // make a real request to an external site
202
207
$client = new Client();
203
- $client->request('GET', 'http://symfony.com ');
208
+ $client->request('GET', '/ ');
204
209
205
210
// select and click on a link
206
211
$link = $crawler->selectLink('Documentation')->link();
@@ -217,9 +222,8 @@ also delete all the cookies::
217
222
218
223
use Acme\Client;
219
224
220
- // make a real request to an external site
221
225
$client = new Client();
222
- $client->request('GET', 'http://symfony.com ');
226
+ $client->request('GET', '/ ');
223
227
224
228
// delete history
225
229
$client->restart();
0 commit comments