equal
deleted
inserted
replaced
57 * and can be used to send multiple requests. |
57 * and can be used to send multiple requests. |
58 * |
58 * |
59 * <p> An {@code HttpClient} provides configuration information, and resource |
59 * <p> An {@code HttpClient} provides configuration information, and resource |
60 * sharing, for all requests send through it. |
60 * sharing, for all requests send through it. |
61 * |
61 * |
62 * <p> Requests can be made either synchronously or asynchronously: |
62 * <p> A {@linkplain BodyHandler BodyHandler} must be supplied for each {@link |
|
63 * HttpRequest} sent. The {@code BodyHandler} determines how to handle the |
|
64 * response body, if any. Once an {@linkplain HttpResponse} is received, the |
|
65 * headers, response code, and body (typically) are available. Whether the |
|
66 * response body bytes has been read or not depends on the type {@code <T>} of |
|
67 * the response body. |
|
68 * |
|
69 * <p> Requests can be sent either synchronously or asynchronously: |
63 * <ul> |
70 * <ul> |
64 * <li>{@link HttpClient#send(HttpRequest, BodyHandler)} blocks |
71 * <li>{@link HttpClient#send(HttpRequest, BodyHandler)} blocks |
65 * until the request has been sent and the response has been received.</li> |
72 * until the request has been sent and the response has been received.</li> |
66 * |
73 * |
67 * <li>{@link HttpClient#sendAsync(HttpRequest, BodyHandler)} sends the |
74 * <li>{@link HttpClient#sendAsync(HttpRequest, BodyHandler)} sends the |
70 * CompletableFuture}<{@linkplain HttpResponse}>. The {@code |
77 * CompletableFuture}<{@linkplain HttpResponse}>. The {@code |
71 * CompletableFuture} completes when the response becomes available. The |
78 * CompletableFuture} completes when the response becomes available. The |
72 * returned {@code CompletableFuture} can be combined in different ways to |
79 * returned {@code CompletableFuture} can be combined in different ways to |
73 * declare dependencies among several asynchronous tasks.</li> |
80 * declare dependencies among several asynchronous tasks.</li> |
74 * </ul> |
81 * </ul> |
75 * |
|
76 * <p> A {@linkplain BodyHandler BodyHandler} must be supplied for each {@code |
|
77 * HttpRequest} sent. The {@code BodyHandler} determines how to handle the |
|
78 * response body, if any. Once an {@linkplain HttpResponse} is received, the |
|
79 * headers, response code, and body (typically) are available. Whether the |
|
80 * response body bytes has been read or not depends on the type {@code <T>} of |
|
81 * the response body. |
|
82 * |
82 * |
83 * <p><b>Synchronous Example</b> |
83 * <p><b>Synchronous Example</b> |
84 * <pre>{@code HttpClient client = HttpClient.newBuilder() |
84 * <pre>{@code HttpClient client = HttpClient.newBuilder() |
85 * .version(Version.HTTP_1) |
85 * .version(Version.HTTP_1) |
86 * .followRedirects(Redirect.SAME_PROTOCOL) |
86 * .followRedirects(Redirect.SAME_PROTOCOL) |
98 * .header("Content-Type", "application/json") |
98 * .header("Content-Type", "application/json") |
99 * .POST(BodyPublisher.fromFile(Paths.get("file.json"))) |
99 * .POST(BodyPublisher.fromFile(Paths.get("file.json"))) |
100 * .build(); |
100 * .build(); |
101 * client.sendAsync(request, BodyHandler.asString()) |
101 * client.sendAsync(request, BodyHandler.asString()) |
102 * .thenApply(HttpResponse::body) |
102 * .thenApply(HttpResponse::body) |
103 * .thenAccept(System.out::println) |
103 * .thenAccept(System.out::println); }</pre> |
104 * .join(); }</pre> |
|
105 * |
104 * |
106 * <p> <a id="securitychecks"></a><b>Security checks</b></a> |
105 * <p> <a id="securitychecks"></a><b>Security checks</b></a> |
107 * |
106 * |
108 * <p> If a security manager is present then security checks are performed by |
107 * <p> If a security manager is present then security checks are performed by |
109 * the HTTP Client's sending methods. An appropriate {@link URLPermission} is |
108 * the HTTP Client's sending methods. An appropriate {@link URLPermission} is |