添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
@NoImplement
public interface HttpClient
Object that sends an HTTP request, and returns the response. Notice it must be started to be used and stopped to be disposed properly. Blocking and non-blocking options are available to execute requests. To extends it's functionality and not depend on API changes, this object should be used internally instead of decorated.
Since:

Method Summary

All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method and Description default CompletableFuture < WebSocket > openWebSocket ( HttpRequest request, HttpRequestOptions requestOptions, String socketId, WebSocketCallback callback)
Opens a new WebSocket by adding the proper upgrade header to the given request
default CompletableFuture < WebSocket > openWebSocket ( HttpRequest request, String socketId, WebSocketCallback callback)
Opens a new WebSocket by adding the proper upgrade header to the given request
default HttpResponse send ( HttpRequest request)
Same as send(HttpRequest, HttpRequestOptions) but using default options.
HttpResponse send ( HttpRequest request, HttpRequestOptions options)
Sends a HttpRequest blocking the current thread until a response is available or the request times out.
default HttpResponse send ( HttpRequest request, int responseTimeout, boolean followRedirects, HttpAuthentication authentication)
Deprecated. CompletableFuture < HttpResponse > sendAsync ( HttpRequest request, HttpRequestOptions options)
Sends a HttpRequest without blocking the current thread.
default CompletableFuture < HttpResponse > sendAsync ( HttpRequest request, int responseTimeout, boolean followRedirects, HttpAuthentication authentication)
Deprecated. default HttpResponse send( HttpRequest request, int responseTimeout, boolean followRedirects, HttpAuthentication authentication) throws IOException , TimeoutException
Sends a HttpRequest blocking the current thread until a response is available or the request times out.
Parameters:
request - the HttpRequest to send
responseTimeout - the time (in milliseconds) to wait for a response
followRedirects - whether or not to follow redirect responses
authentication - the optional HttpAuthentication to use
Returns:
the received HttpResponse
Throws:
IOException - if an error occurs while executing
TimeoutException - if responseTimeout is exceeded
throws IOException , TimeoutException
Same as send(HttpRequest, HttpRequestOptions) but using default options.
Parameters:
request - the HttpRequest to send
Returns:
the received HttpResponse
Throws:
IOException - if an error occurs while executing
TimeoutException - if responseTimeout is exceeded
HttpResponse send(HttpRequest request,
                  HttpRequestOptions options)
           throws IOException,
                  TimeoutException
Sends a HttpRequest blocking the current thread until a response is available or the request times out.
Parameters:
request - the HttpRequest to send
options - the HttpRequestOptions to use
Returns:
the received HttpResponse
Throws:
IOException - if an error occurs while executing
TimeoutException - if responseTimeout is exceeded

sendAsync

@Deprecated
default CompletableFuture<HttpResponse> sendAsync(HttpRequest request,
                                                              int responseTimeout,
                                                              boolean followRedirects,
                                                              HttpAuthentication authentication)
Sends a HttpRequest without blocking the current thread. When a response is available or the request times out the returned CompletableFuture will be completed. Be aware that the response body processing will be deferred so that the response can be processed even when a large body is still being received. If the full response is needed right away then the provided HttpResponse must be read in a different thread so that it does not block the HttpClient threads handling the response. It's therefore recommended to use CompletableFuture.get() or any of the async methods available, such as CompletableFuture.whenCompleteAsync(BiConsumer, Executor) , to handle the response is those scenarios since they guarantee executing on a different thread.
Parameters:
request - the HttpRequest to send
responseTimeout - the time (in milliseconds) to wait for a response
followRedirects - whether or not to follow redirect responses
authentication - the optional HttpAuthentication to use
Returns:
a CompletableFuture that will complete once the HttpResponse is available

sendAsync

default CompletableFuture<HttpResponse> sendAsync(HttpRequest request)
Same as sendAsync(HttpRequest, HttpRequestOptions) but using default options.
Parameters:
request - the HttpRequest to send
Returns:
a CompletableFuture that will complete once the HttpResponse is available

sendAsync

CompletableFuture<HttpResponse> sendAsync(HttpRequest request,
                                          HttpRequestOptions options)
Sends a HttpRequest without blocking the current thread. When a response is available or the request times out the returned CompletableFuture will be completed. Be aware that the response body processing will be deferred so that the response can be processed even when a large body is still being received. If the full response is needed right away then the provided HttpResponse must be read in a different thread so that it does not block the HttpClient threads handling the response. It's therefore recommended to use CompletableFuture.get() or any of the async methods available, such as CompletableFuture.whenCompleteAsync(BiConsumer, Executor) , to handle the response is those scenarios since they guarantee executing on a different thread.
Parameters:
request - the HttpRequest to send
options - the HttpRequestOptions to use
Returns:
a CompletableFuture that will complete once the HttpResponse is available

openWebSocket

default CompletableFuture<WebSocket> openWebSocket(HttpRequest request,
                                                   String socketId,
                                                   WebSocketCallback callback)
Opens a new WebSocket by adding the proper upgrade header to the given request
Parameters:
request - a HttpRequest to the target WebSocket endpoint
socketId - the id of the obtained socket
callback - the callback that will receive the associated socket events
Returns:
a future WebSocket
Since:
4.2.0

openWebSocket

default CompletableFuture<WebSocket> openWebSocket(HttpRequest request,
                                                   HttpRequestOptions requestOptions,
                                                   String socketId,
                                                   WebSocketCallback callback)
Opens a new WebSocket by adding the proper upgrade header to the given request
Parameters:
request - a HttpRequest to the target WebSocket endpoint
requestOptions - the request options
socketId - the id of the obtained socket
callback - the callback that will receive the associated socket events
Returns:
a future WebSocket
Since:
4.2.0