类 RequestBuilder


  • public class RequestBuilder
    extends Object
    Http Request builder
    作者:
    Liu Dong
    • 方法详细资料

      • timeout

        public T timeout​(Duration timeout)
        The timeout for one request to return response, do not include connect time. This setting will override timeout setting in HttpClient.
        参数:
        timeout - must larger than zero
      • userAgent

        public T userAgent​(String userAgent)
        The request user-agent. This setting will override timeout setting in HttpClient.
        参数:
        userAgent - cannot be null
      • referer

        public T referer​(String referer)
        Set request referer header.
        参数:
        referer - cannot be null
      • headers

        public T headers​(Collection<? extends Header> headers)
        Set request headers.
      • headers

        public final T headers​(Header... headers)
        Set request headers.
      • headers

        public final T headers​(Map<String,​String> map)
        Set request headers.
      • cookies

        public T cookies​(Collection<? extends Cookie> cookies)
        Set request cookies.
      • cookies

        public final T cookies​(Cookie... cookies)
        Set request cookies.
      • cookies

        public final T cookies​(Map<String,​String> map)
        Set request cookies.
      • params

        public T params​(Collection<? extends Param> params)
        Set url query params.
        参数:
        params - the parameters
      • params

        public T params​(Collection<? extends Param> params,
                        Charset charset)
        Set url query params.
        参数:
        params - the parameters
        charset - charset used to encode params to query string
      • params

        public final T params​(Param... params)
        Set url query params.
        参数:
        params - the parameters
      • params

        public final T params​(Map<String,​String> map)
        Set url query params.
        参数:
        map - the parameters
      • params

        public final T params​(Map<String,​String> map,
                              Charset charset)
        Set url query params.
        参数:
        map - the parameters
        charset - charset used to encode params to query string
      • body

        public T body​(Body<?> body)
        Set request body. To get ordinary bodies, see Bodies
      • jsonBody

        public T jsonBody​(@Nullable Object body,
                          Charset charset)
        Set a json request body. This is a convenient method for set a body by a json request body. This method uses a JsonMarshaller from the Client, If no JsonMarshaller was provided, A JsonMarshallerNotFoundException would be thrown.
        参数:
        body - the value to encode to json
      • jsonBody

        public T jsonBody​(@Nullable Object body)
        Set a json request body, with charset utf-8. This is a convenient method for set a body by a json request body. This method uses a JsonMarshaller from the Client, If no JsonMarshaller was provided, A JsonMarshallerNotFoundException would be thrown.
        参数:
        body - the value to encode to json
      • acceptCompressed

        public T acceptCompressed​(boolean acceptCompressed)
        Auto set Accept-Encoding header for request. This setting will override setting in ClientBuilder.
      • basicAuth

        public T basicAuth​(String user,
                           char[] password)
        Set http Basic Authentication
      • build

        public Request build()
        Build a immutable request.
        返回:
        the request.