类 SimpleHttpClient

java.lang.Object
com.alibaba.csp.sentinel.transport.heartbeat.client.SimpleHttpClient

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.

作者:
leyou, Leo Li
  • 构造器详细资料

    • SimpleHttpClient

      public SimpleHttpClient()
  • 方法详细资料

    • get

      public SimpleHttpResponse get(SimpleHttpRequest request) throws IOException
      Execute a GET HTTP request.
      参数:
      request - HTTP request
      返回:
      the response if the request is successful
      抛出:
      IOException - when connection cannot be established or the connection is interrupted
    • post

      public SimpleHttpResponse post(SimpleHttpRequest request) throws IOException
      Execute a POST HTTP request.
      参数:
      request - HTTP request
      返回:
      the response if the request is successful
      抛出:
      IOException - when connection cannot be established or the connection is interrupted