Top Description Methods
org.apache.hc.client5.http.classic

public Interface HttpClient

Known Direct Implementers
org.apache.hc.client5.http.impl.classic.CloseableHttpClient
Imports
java.io.Closeable, .IOException, org.apache.hc.core5.http.ClassicHttpRequest, .ClassicHttpResponse, .HttpHost, .HttpResponse, org.apache.hc.core5.http.io.HttpClientResponseHandler, org.apache.hc.core5.http.protocol.HttpContext

This interface represents only the most basic contract for HTTP request execution. It imposes no restrictions or particular details on the request execution process and leaves the specifics of state management, authentication and redirect handling up to individual implementations.
Since
4.0

Method Summary

Modifier and TypeMethod and Description
public HttpResponse

Returns:

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
execute
(ClassicHttpRequest
the request to execute
request
)

Deprecated It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(ClassicHttpRequest, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client.
Executes HTTP request using the default context.
public HttpResponse

Returns:

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
execute
(ClassicHttpRequest
the request to execute
request
,
HttpContext
the context to use for the execution, or null to use the default context
context
)

Deprecated It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client.
Executes HTTP request using the given context.
public ClassicHttpResponse

Returns:

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
execute
(HttpHost
the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
target
,
ClassicHttpRequest
the request to execute
request
)

Deprecated It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client.
Executes HTTP request using the default context.
public HttpResponse

Returns:

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
execute
(HttpHost
the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
target
,
ClassicHttpRequest
the request to execute
request
,
HttpContext
the context to use for the execution, or null to use the default context
context
)

Deprecated It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client.
Executes HTTP request using the given context.
public <T> T

Returns:

the response object as generated by the response handler.
execute
(ClassicHttpRequest
the request to execute
request
,
HttpClientResponseHandler<? extends T>
the response handler
responseHandler
)

Executes HTTP request using the default context and processes the response using the given response handler.

public <T> T

Returns:

the response object as generated by the response handler.
execute
(ClassicHttpRequest
the request to execute
request
,
HttpContext
the context to use for the execution, or null to use the default context
context
,
HttpClientResponseHandler<? extends T>
the response handler
responseHandler
)

Executes HTTP request using the given context and processes the response using the given response handler.

public <T> T

Returns:

the response object as generated by the response handler.
execute
(HttpHost
the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
target
,
ClassicHttpRequest
the request to execute
request
,
HttpClientResponseHandler<? extends T>
the response handler
responseHandler
)

Executes HTTP request to the target using the default context and processes the response using the given response handler.

public <T> T

Returns:

the response object as generated by the response handler.
execute
(HttpHost
the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
target
,
ClassicHttpRequest
the request to execute
request
,
HttpContext
the context to use for the execution, or null to use the default context
context
,
HttpClientResponseHandler<? extends T>
the response handler
responseHandler
)

Executes HTTP request to the target using the given context and processes the response using the given response handler.

public default ClassicHttpResponse

Returns:

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client. The response returned by this method must be closed with Closeable#close() in order ensure deallocation of system resources.
executeOpen
(HttpHost
the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
target
,
ClassicHttpRequest
the request to execute
request
,
HttpContext
the context to use for the execution, or null to use the default context
context
)

Executes the request and opens the response stream using the given context.

Method Detail

executeback to summary
public HttpResponse execute(ClassicHttpRequest request) throws IOException

Deprecated

It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(ClassicHttpRequest, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client. For special cases one can still use executeOpen(HttpHost, ClassicHttpRequest, HttpContext) to keep the response object open after the request execution.

Executes HTTP request using the default context.

Parameters
request:ClassicHttpRequest

the request to execute

Returns:HttpResponse

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

Annotations
@Deprecated
Exceptions
IOException:
in case of a problem or the connection was aborted
See Also
execute(ClassicHttpRequest, HttpClientResponseHandler), executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
executeback to summary
public HttpResponse execute(ClassicHttpRequest request, HttpContext context) throws IOException

Deprecated

It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client. For special cases one can still use executeOpen(HttpHost, ClassicHttpRequest, HttpContext) to keep the response object open after the request execution.

Executes HTTP request using the given context.

Parameters
request:ClassicHttpRequest

the request to execute

context:HttpContext

the context to use for the execution, or null to use the default context

Returns:HttpResponse

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

Annotations
@Deprecated
Exceptions
IOException:
in case of a problem or the connection was aborted
See Also
execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler), executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
executeback to summary
public ClassicHttpResponse execute(HttpHost target, ClassicHttpRequest request) throws IOException

Deprecated

It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client. For special cases one can still use executeOpen(HttpHost, ClassicHttpRequest, HttpContext) to keep the response object open after the request execution.

Executes HTTP request using the default context.

Parameters
target:HttpHost

the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.

request:ClassicHttpRequest

the request to execute

Returns:ClassicHttpResponse

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

Annotations
@Deprecated
Exceptions
IOException:
in case of a problem or the connection was aborted
See Also
execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler), executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
executeback to summary
public HttpResponse execute(HttpHost target, ClassicHttpRequest request, HttpContext context) throws IOException

Deprecated

It is strongly recommended to use execute methods with HttpClientResponseHandler such as execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler) in order to ensure automatic resource deallocation by the client. For special cases one can still use executeOpen(HttpHost, ClassicHttpRequest, HttpContext) to keep the response object open after the request execution.

Executes HTTP request using the given context.

Parameters
target:HttpHost

the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.

request:ClassicHttpRequest

the request to execute

context:HttpContext

the context to use for the execution, or null to use the default context

Returns:HttpResponse

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

Annotations
@Deprecated
Exceptions
IOException:
in case of a problem or the connection was aborted
See Also
execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler), executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
executeback to summary
public <T> T execute(ClassicHttpRequest request, HttpClientResponseHandler<? extends T> responseHandler) throws IOException

Executes HTTP request using the default context and processes the response using the given response handler.

Implementing classes are required to ensure that the content entity associated with the response is fully consumed and the underlying connection is released back to the connection manager automatically in all cases relieving individual HttpClientResponseHandlers from having to manage resource deallocation internally.

Parameters
request:ClassicHttpRequest

the request to execute

responseHandler:HttpClientResponseHandler<? extends T>

the response handler

Returns:T

the response object as generated by the response handler.

Exceptions
IOException:
in case of a problem or the connection was aborted
executeback to summary
public <T> T execute(ClassicHttpRequest request, HttpContext context, HttpClientResponseHandler<? extends T> responseHandler) throws IOException

Executes HTTP request using the given context and processes the response using the given response handler.

Implementing classes are required to ensure that the content entity associated with the response is fully consumed and the underlying connection is released back to the connection manager automatically in all cases relieving individual HttpClientResponseHandlers from having to manage resource deallocation internally.

Parameters
request:ClassicHttpRequest

the request to execute

context:HttpContext

the context to use for the execution, or null to use the default context

responseHandler:HttpClientResponseHandler<? extends T>

the response handler

Returns:T

the response object as generated by the response handler.

Exceptions
IOException:
in case of a problem or the connection was aborted
executeback to summary
public <T> T execute(HttpHost target, ClassicHttpRequest request, HttpClientResponseHandler<? extends T> responseHandler) throws IOException

Executes HTTP request to the target using the default context and processes the response using the given response handler.

Implementing classes are required to ensure that the content entity associated with the response is fully consumed and the underlying connection is released back to the connection manager automatically in all cases relieving individual HttpClientResponseHandlers from having to manage resource deallocation internally.

Parameters
target:HttpHost

the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.

request:ClassicHttpRequest

the request to execute

responseHandler:HttpClientResponseHandler<? extends T>

the response handler

Returns:T

the response object as generated by the response handler.

Exceptions
IOException:
in case of a problem or the connection was aborted
executeback to summary
public <T> T execute(HttpHost target, ClassicHttpRequest request, HttpContext context, HttpClientResponseHandler<? extends T> responseHandler) throws IOException

Executes HTTP request to the target using the given context and processes the response using the given response handler.

Implementing classes are required to ensure that the content entity associated with the response is fully consumed and the underlying connection is released back to the connection manager automatically in all cases relieving individual HttpClientResponseHandlers from having to manage resource deallocation internally.

Parameters
target:HttpHost

the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.

request:ClassicHttpRequest

the request to execute

context:HttpContext

the context to use for the execution, or null to use the default context

responseHandler:HttpClientResponseHandler<? extends T>

the response handler

Returns:T

the response object as generated by the response handler.

Exceptions
IOException:
in case of a problem or the connection was aborted
executeOpenback to summary
public default ClassicHttpResponse executeOpen(HttpHost target, ClassicHttpRequest request, HttpContext context) throws IOException

Executes the request and opens the response stream using the given context.

Parameters
target:HttpHost

the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.

request:ClassicHttpRequest

the request to execute

context:HttpContext

the context to use for the execution, or null to use the default context

Returns:ClassicHttpResponse

the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client. The response returned by this method must be closed with Closeable#close() in order ensure deallocation of system resources.

Annotations
@SuppressWarnings:deprecation
Exceptions
IOException:
in case of a problem or the connection was aborted
Since
5.2