public class SimpleHttpClient extends Object
A very simple HTTP client that only supports GET/POST method and plain text request body. The Content-Type header is always set as
application/x-www-form-urlencoded. All parameters in the request will be encoded using
URLEncoder.encode(String, String).
The result of a HTTP invocation will be wrapped as a SimpleHttpResponse. Content in response body
will be automatically decoded to string with provided charset.
This is a blocking and synchronous client, so an invocation will await the response until timeout exceed.
Note that this is a very NAIVE client, Content-Length must be specified in the
HTTP response header, otherwise, the response body will be dropped. All other body type such as
Transfer-Encoding: chunked, Transfer-Encoding: deflate are not supported.
| Constructor and Description |
|---|
SimpleHttpClient() |
| Modifier and Type | Method and Description |
|---|---|
SimpleHttpResponse |
get(SimpleHttpRequest request)
Execute a GET HTTP request.
|
SimpleHttpResponse |
post(SimpleHttpRequest request)
Execute a POST HTTP request.
|
public SimpleHttpResponse get(SimpleHttpRequest request) throws IOException
request - HTTP requestIOException - when connection cannot be established or the connection is interruptedpublic SimpleHttpResponse post(SimpleHttpRequest request) throws IOException
request - HTTP requestIOException - when connection cannot be established or the connection is interruptedCopyright © 2022 Alibaba Group. All rights reserved.