Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e6b444

Browse files
committed
Final changes
1 parent2ba0598 commit5e6b444

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

‎components/http_client.rst‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ Installation
1919
2020
$ composer require symfony/http-client
2121
22-
Alternatively, you can clone the `<https://github.com/symfony/http-client>`_
23-
repository.
24-
2522
..include::/components/require_autoload.rst.inc
2623

2724
Basic Usage
@@ -92,12 +89,29 @@ method to perform all kinds of HTTP requests::
9289
$response = $httpClient->request('PUT', 'https://...');
9390
// ...
9491

92+
Responses are always asynchronous, so they are ready as soon as the response
93+
HTTP headers are received, instead of waiting to receive the entire response
94+
contents::
95+
96+
$response = $httpClient->request('GET', 'http://releases.ubuntu.com/18.04.2/ubuntu-18.04.2-desktop-amd64.iso');
97+
98+
// code execution continues immediately; it doesn't wait to receive the response
99+
// you can get the value of any HTTP response header
100+
$contentType = $response->getHeaders()['content-type'][0];
101+
102+
// trying to get the response contents will block the execution until
103+
// the full response contents are received
104+
$contents = $response->getContent();
105+
106+
This component also supports:ref:`streaming responses<http-client-streaming-responses>`
107+
for full asynchronous applications.
108+
95109
Authentication
96110
~~~~~~~~~~~~~~
97111

98112
The HTTP client supports different authentication mechanisms. They can be
99113
defined globally when creating the client (to apply it to all requests) and to
100-
each request (which overrides any global authentication, if defined)::
114+
each request (which overrides any global authentication)::
101115

102116
// Use the same authentication for all requests
103117
$httpClient = HttpClient::create([
@@ -219,13 +233,6 @@ Concurrent Requests
219233
.. TODO
220234
221235
222-
Asynchronous Requests
223-
~~~~~~~~~~~~~~~~~~~~~
224-
225-
226-
.. TODO see https://gist.github.com/tgalopin/a84a11ece0621b8a79ed923afe015b3c
227-
228-
229236
Processing Responses
230237
--------------------
231238

@@ -244,12 +251,14 @@ following methods::
244251
// gets the response body as a string
245252
$content = $response->getContent();
246253

247-
// returns info coming from the transport layer, such as "raw_headers",
254+
// returns info coming from the transport layer, such as "response_headers",
248255
// "redirect_count", "start_time", "redirect_url", etc.
249256
$httpInfo = $response->getInfo();
250257
// you can get individual info too
251258
$startTime = $response->getInfo('start_time');
252259

260+
.._http-client-streaming-responses::
261+
253262
Streaming Responses
254263
~~~~~~~~~~~~~~~~~~~
255264

@@ -415,8 +424,7 @@ the available config options:
415424
max_redirects:7
416425
max_host_connections:10
417426
418-
If you want to define multiple HTTP and API clients, use this other expanded
419-
configuration:
427+
If you want to define multiple HTTP clients, use this other expanded configuration:
420428

421429
..code-block::yaml
422430
@@ -432,11 +440,6 @@ configuration:
432440
max_host_connections:10
433441
max_redirects:7
434442
435-
api_clients:
436-
github:
437-
base_uri:'https://api.github.com'
438-
headers:[{ 'Accept': 'application/vnd.github.v3+json' }]
439-
440443
Injecting the HTTP Client Into Services
441444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442445

@@ -458,17 +461,16 @@ service by type-hinting a constructor argument with the
458461

459462
If you have several clients, you must use any of the methods defined by Symfony
460463
to ref:`choose a specific service <services-wire-specific-service>`. Each client
461-
has a service associated with it whose name follows the pattern
462-
``client type + client name`` (e.g. ``http_client.crawler``, ``api_client.github``).
464+
has a unique service named after its configuration.
463465

464466
..code-block::yaml
465467
466468
# config/services.yaml
467469
services:
468470
# ...
469471
470-
# whenever a service type-hintsApiClientInterface, inject the GitHub client
471-
Symfony\Contracts\HttpClient\ApiClientInterface:'@api_client.github'
472+
# whenever a service type-hintsHttpClientInterface, inject the GitHub client
473+
Symfony\Contracts\HttpClient\HttpClientInterface:'@api_client.github'
472474
473475
# inject the HTTP client called 'crawler' into this argument of this service
474476
App\Some\Service:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp