- java.lang.Object
-
- net.dongliu.cute.http.RequestContext
-
public class RequestContext extends Object
For carrying http client for chained call.
-
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 TacceptCompressed(boolean acceptCompressed)Auto set Accept-Encoding header for request.TbasicAuth(String user, char[] password)Set http Basic AuthenticationTbasicAuth(PasswordAuthentication basicAuth)Set http Basic AuthenticationTbody(Body<?> body)Set request body.Requestbuild()Build a immutable request.Tcookies(Collection<? extends Cookie> cookies)Set request cookies.Tcookies(Map<String,String> map)Set request cookies.Tcookies(Cookie... cookies)Set request cookies.Theaders(Collection<? extends Header> headers)Set request headers.Theaders(Map<String,String> map)Set request headers.Theaders(Header... headers)Set request headers.TjsonBody(@Nullable Object body)Set a json request body, with charset utf-8.TjsonBody(@Nullable Object body, Charset charset)Set a json request body.Tparams(Collection<? extends Param> params)Set url query params.Tparams(Collection<? extends Param> params, Charset charset)Set url query params.Tparams(Map<String,String> map)Set url query params.Tparams(Map<String,String> map, Charset charset)Set url query params.Tparams(Param... params)Set url query params.Treferer(String referer)Set request referer header.protected RequestContextself()ResponseContextsend()Build http request, and send out sync.AsyncResponseContextsendAsync()Build http request, and send out sync.Ttimeout(Duration timeout)The timeout for one request to return response, do not include connect time.TuserAgent(String userAgent)The request user-agent.
-
-
-
方法详细资料
-
send
public ResponseContext send()
Build http request, and send out sync.- 抛出:
RequestInterruptedException- if send is interruptedUncheckedIOException- if io error occurred
-
sendAsync
public AsyncResponseContext sendAsync()
Build http request, and send out sync.
-
self
protected RequestContext self()
-
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.
-
cookies
public T cookies(Collection<? extends Cookie> cookies)
Set request cookies.
-
cookies
public final T cookies(Cookie... cookies)
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 parameterscharset- 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 parameterscharset- charset used to encode params to query string
-
jsonBody
public T jsonBody(@Nullable Object body, Charset charset)
Set a json request body. This is a convenient method for set abodyby a json request body. This method uses aJsonMarshallerfrom theClient, If no JsonMarshaller was provided, AJsonMarshallerNotFoundExceptionwould 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 abodyby a json request body. This method uses aJsonMarshallerfrom theClient, If no JsonMarshaller was provided, AJsonMarshallerNotFoundExceptionwould 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
-
basicAuth
public T basicAuth(PasswordAuthentication basicAuth)
Set http Basic Authentication
-
build
public Request build()
Build a immutable request.- 返回:
- the request.
-
-