@@ -162,7 +162,7 @@ requests and the specific headers for each request::
162
162
// of the same header if defined globally by the HTTP client
163
163
$response = $httpClient->request('POST', 'https://...', [
164
164
'headers' => [
165
- 'Content-type ' => 'text/plain',
165
+ 'Content-Type ' => 'text/plain',
166
166
],
167
167
]);
168
168
@@ -190,7 +190,8 @@ processed automatically when making the requests::
190
190
]);
191
191
192
192
When uploading data with the ``POST `` method, if you don't define the
193
- ``Content-Type `` HTTP header explicitly, Symfony adds the required
193
+ ``Content-Type `` HTTP header explicitly, Symfony assumes that you're uploading
194
+ form data and adds the required
194
195
``'Content-Type: application/x-www-form-urlencoded' `` header for you.
195
196
196
197
When uploading JSON payloads, use the ``json `` option instead of ``body ``. The
@@ -270,7 +271,7 @@ response sequentially instead of waiting for the entire response::
270
271
// optional: if you don't want to buffer the response in memory
271
272
'buffer' => false,
272
273
// optional: to display details about the response progress
273
- 'on_progress' => function (int $dlNow, int $dlSize, array $info) {
274
+ 'on_progress' => function (int $dlNow, int $dlSize, array $info): void {
274
275
// ...
275
276
},
276
277
]);
@@ -290,10 +291,11 @@ response sequentially instead of waiting for the entire response::
290
291
Handling Exceptions
291
292
~~~~~~~~~~~~~~~~~~~
292
293
293
- When an HTTP error happens ( status code 3xx, 4xx or 5xx) your code is expected
294
- to handle it by checking the status code of the response . If you don't do that,
295
- the ``getHeaders() `` and ``getContent() `` methods throw an appropriate exception::
294
+ When the HTTP status code of the response is not in the 200-299 range (i.e. 3xx,
295
+ 4xx or 5xx) your code is expected to handle it . If you don't do that, the
296
+ ``getHeaders() `` and ``getContent() `` methods throw an appropriate exception::
296
297
298
+ // the response of this request will be a 403 HTTP error
297
299
$response = $httpClient->request('GET', 'https://httpbin.org/status/403');
298
300
299
301
// this code results in a Symfony\Component\HttpClient\Exception\ClientException
@@ -506,15 +508,15 @@ responses dynamically when it's called::
506
508
use Symfony\Component\HttpClient\Response\MockResponse;
507
509
508
510
$callback = function ($method, $url, $options) {
509
- return new MockResponse('...';
511
+ return new MockResponse('...') ;
510
512
};
511
513
512
514
$client = new MockHttpClient($callback);
513
515
$response = $client->request('...'); // calls $callback to get the response
514
516
515
517
The responses provided to the mock client don't have to be instances of
516
518
``MockResponse ``. Any class implementing ``ResponseInterface `` will work (e.g.
517
- ``$this->getMockBuilder (ResponseInterface::class)->getMock( ) ``).
519
+ ``$this->createMock (ResponseInterface::class) ``).
518
520
519
521
However, using ``MockResponse `` allows simulating chunked responses and timeouts::
520
522
0 commit comments