public interface HttpRequest
| Modifier and Type | Method and Description |
|---|---|
HttpRequest |
acceptGzip()
Add
Accept-Encoding header with "gzip, deflate" value. |
HttpRequest |
acceptJson()
Add header to specify that accept type
is
"application/json". |
HttpRequest |
acceptLanguage(String lang)
Add
Accept-Language header. |
HttpRequest |
acceptXml()
Add header to specify that accept type
is
"application/xml". |
HttpRequest |
addAcceptEncoding(String encoding)
Add
Accept-Encoding header. |
HttpRequest |
addCookie(Cookie cookie)
Add cookie to http request.
|
HttpRequest |
addCookie(String name,
String value)
Add cookie to http request.
|
HttpRequest |
addCsrfToken(String token)
Add CSRF Token to http header (
X-Csrf-Token header). |
HttpRequest |
addHeader(HttpHeader header)
Add header.
|
HttpRequest |
addHeader(String name,
String value)
Add header.
|
HttpRequest |
addIfMatch(String etag)
Add
If-Match header with expected value. |
HttpRequest |
addIfModifiedSince(Date date)
Add
If-Modified-Since value with expected date (date will be translated
as GMT raw). |
HttpRequest |
addIfNoneMatch(String etag)
Add
If-None-Match header with expected value. |
HttpRequest |
addIfUnmodifiedSince(Date date)
Add
If-Unmodified-Since value with expected date (date will be translated
as GMT raw). |
HttpRequest |
addOrigin(String origin)
Add
Origin header. |
HttpRequest |
addQueryParam(String name,
String value)
Add query parameters: a query parameter is a parameter that will
follow the
? character in the request URL. |
HttpRequest |
addQueryParams(HttpParameter parameter,
HttpParameter... parameters)
Add collection of query parameters: a query parameter is a parameter that will
follow the
? character in the request URL. |
HttpRequest |
addReferer(String referer)
Add
Referer header. |
HttpRequest |
addXHttpMethodOverride(String method)
Add
X-Http-Method-Override value with HTTP verb to override. |
HttpRequest |
asFormUrlEncoded()
Add header to specify that content type
is
"application/x-www-form-urlencoded". |
HttpRequest |
asJson()
Add header to specify that content type
is
"application/json". |
HttpRequest |
asXml()
Add header to specify that content type
is
"application/xml". |
HttpRequest |
asXmlHttpRequest()
Most library (such as jQuery) add automatically header
named "X-Requested-With" with value "XMLHttpRequest", this
method add this header and can be used to simulate ajax
call.
|
HttpResponse |
execute()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpResponse |
executeJson()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpResponse |
executeXml()
Execute request and return http response: execution is synchronous and will block until
response is available.
|
HttpUrl |
getEndpoint()
Request URL.
|
HttpMethod |
getMethod()
Return http request method.
|
HttpRequest |
overrideDelete()
Add
X-Http-Method-Override value with DELETE value. |
HttpRequest |
overridePut()
Add @{code X-Http-Method-Override} value with
PUT value. |
HttpRequest |
setBody(HttpRequestBody body)
Set request body.
|
HttpRequest |
withUserAgent(String userAgent)
Add
User-Agent header to http request. |
HttpUrl getEndpoint()
HttpMethod getMethod()
HttpRequest addHeader(String name, String value)
name - Header name.value - Header value.NullPointerException - If name or value is null.IllegalArgumentException - if name is blank.addHeader(HttpHeader)HttpRequest addHeader(HttpHeader header)
header - The header.NullPointerException - If header is null.HttpRequest addQueryParam(String name, String value)
? character in the request URL.name - Parameter name.value - Parameter value.HttpRequest addQueryParams(HttpParameter parameter, HttpParameter... parameters)
? character in the request URL.parameter - Parameter.parameters - Optional next parameters.HttpRequest setBody(HttpRequestBody body)
"POST", "PUT" or "PATCH" request only, otherwise
it will throw UnsupportedOperationException exception.body - Body request.UnsupportedOperationException - If request method does not allow body (i.e GET, HEAD or DELETE).HttpRequest asXmlHttpRequest()
HttpHeaders.REQUESTED_WITH,
HttpHeaders.XML_HTTP_REQUESTHttpRequest asFormUrlEncoded()
"application/x-www-form-urlencoded".MediaType.APPLICATION_FORM_URL_ENCODED,
https://tools.ietf.org/html/draft-hoehrmann-urlencoded-01HttpRequest asJson()
"application/json".HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON,
https://www.w3.org/Protocols/rfc1341/4_Content-Type.htmlHttpRequest asXml()
"application/xml".HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML,
https://www.w3.org/Protocols/rfc1341/4_Content-Type.htmlHttpRequest acceptJson()
"application/json".HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON,
https://tools.ietf.org/html/rfc7231#section-5.3.2HttpRequest acceptXml()
"application/xml".HttpHeaders.ACCEPT,
MediaType.APPLICATION_XML,
https://tools.ietf.org/html/rfc7231#section-5.3.2HttpRequest acceptLanguage(String lang)
Accept-Language header.lang - Accepted languages.HttpHeaders.ACCEPT_LANGUAGE,
https://tools.ietf.org/html/rfc7231#section-5.3.5HttpRequest addOrigin(String origin)
Origin header.origin - Origin value.HttpHeaders.ORIGIN,
https://tools.ietf.org/html/rfc6454HttpRequest addReferer(String referer)
Referer header.referer - Referer value.HttpHeaders.REFERER,
https://tools.ietf.org/html/rfc7231#section-5.5.2HttpRequest addAcceptEncoding(String encoding)
Accept-Encoding header.encoding - Encoding value.HttpHeaders.ACCEPT_ENCODING,
https://tools.ietf.org/html/rfc7231#section-5.3.4HttpRequest acceptGzip()
Accept-Encoding header with "gzip, deflate" value.HttpHeaders.ACCEPT_ENCODING,
https://tools.ietf.org/html/rfc7231#section-5.3.4,
addAcceptEncoding(String)HttpRequest withUserAgent(String userAgent)
User-Agent header to http request.userAgent - User-Agent value.HttpHeaders.USER_AGENT,
https://tools.ietf.org/html/rfc2616#section-14.43HttpRequest addCookie(Cookie cookie)
cookie - Cookie.HttpHeaders.COOKIE,
https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Cookie,
https://tools.ietf.org/html/rfc6265#section-5.4HttpRequest addCookie(String name, String value)
name - Cookie name.value - Cookie value.NullPointerException - If name or value are null.IllegalArgumentException - If name is empty or blank.HttpHeaders.COOKIE,
addCookie(Cookie),
https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Cookie,
https://tools.ietf.org/html/rfc6265#section-5.4HttpRequest addIfNoneMatch(String etag)
If-None-Match header with expected value.
This header should work with ETag header sent by server
response.etag - ETag value.HttpHeaders.IF_NONE_MATCH,
https://tools.ietf.org/html/rfc7232#section-3.2HttpRequest addIfMatch(String etag)
If-Match header with expected value.
This header should work with ETag header sent by server
response.etag - ETag value.HttpHeaders.IF_MATCH,
https://tools.ietf.org/html/rfc7232#section-3.1HttpRequest addIfModifiedSince(Date date)
If-Modified-Since value with expected date (date will be translated
as GMT raw).date - Date.HttpHeaders.IF_MODIFIED_SINCE,
https://tools.ietf.org/html/rfc7232#section-3.3HttpRequest addIfUnmodifiedSince(Date date)
If-Unmodified-Since value with expected date (date will be translated
as GMT raw).date - Date.HttpHeaders.IF_UNMODIFIED_SINCE,
https://tools.ietf.org/html/rfc7232#section-3.4HttpRequest addXHttpMethodOverride(String method)
X-Http-Method-Override value with HTTP verb to override.
This method is generally used with POST request to override
PUT or DELETE requests.method - Http method to override.HttpHeaders.X_HTTP_METHOD_OVERRIDEHttpRequest addCsrfToken(String token)
X-Csrf-Token header).token - Token value.HttpHeaders.X_CSRF_TOKENHttpRequest overridePut()
PUT value.HttpHeaders.X_HTTP_METHOD_OVERRIDE,
addXHttpMethodOverride(String)HttpRequest overrideDelete()
X-Http-Method-Override value with DELETE value.HttpHeaders.X_HTTP_METHOD_OVERRIDE,
addXHttpMethodOverride(String)HttpResponse execute()
HttpResponse executeJson()
This method automatically add json header (i.e
methods asJson() and acceptJson() will be automatically
be called before execution).
acceptJson(),
asJson()HttpResponse executeXml()
This method automatically add xml header (i.e
methods asXml() and acceptXml() will be automatically
called before execution).
acceptXml(),
asXml()Copyright © 2019. All rights reserved.