-
public class HttpRequestA fluid interface for making HTTP requests using an underlying HttpURLConnection (or sub-class).
Each instance supports making a single request and cannot be reused for further requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceHttpRequest.ConnectionFactoryCreates HTTP connections for urls.
public interfaceHttpRequest.UploadProgressCallback interface for reporting upload progress for a request.
public classHttpRequest.Base64Encodes and decodes to and from Base64 notation.
I am placing this code in the Public Domain. Do with it as you will. Thissoftware comes with no guarantees or warranties but with plenty ofwell-wishing instead! Please visit http://iharder.net/base64 periodicallyto check for updates or to contribute improvements.
public classHttpRequest.HttpRequestExceptionHTTP request exception whose cause is always an IOException
public classHttpRequest.RequestOutputStreamRequest output stream
-
Field Summary
Fields Modifier and Type Field Description public final static StringCHARSET_UTF8public final static StringCONTENT_TYPE_FORMpublic final static StringCONTENT_TYPE_JSONpublic final static StringENCODING_GZIPpublic final static StringHEADER_ACCEPTpublic final static StringHEADER_ACCEPT_CHARSETpublic final static StringHEADER_ACCEPT_ENCODINGpublic final static StringHEADER_AUTHORIZATIONpublic final static StringHEADER_CACHE_CONTROLpublic final static StringHEADER_CONTENT_ENCODINGpublic final static StringHEADER_CONTENT_LENGTHpublic final static StringHEADER_CONTENT_TYPEpublic final static StringHEADER_DATEpublic final static StringHEADER_ETAGpublic final static StringHEADER_EXPIRESpublic final static StringHEADER_IF_NONE_MATCHpublic final static StringHEADER_LAST_MODIFIEDpublic final static StringHEADER_LOCATIONpublic final static StringHEADER_PROXY_AUTHORIZATIONpublic final static StringHEADER_REFERERpublic final static StringHEADER_SERVERpublic final static StringHEADER_USER_AGENTpublic final static StringMETHOD_DELETEpublic final static StringMETHOD_GETpublic final static StringMETHOD_HEADpublic final static StringMETHOD_OPTIONSpublic final static StringMETHOD_POSTpublic final static StringMETHOD_PUTpublic final static StringMETHOD_TRACEpublic final static StringPARAM_CHARSETprivate HttpURLConnectionconnection
-
Constructor Summary
Constructors Constructor Description HttpRequest(CharSequence url, String method)Create HTTP connection wrapper HttpRequest(URL url, String method)Create HTTP connection wrapper
-
Method Summary
Modifier and Type Method Description HttpURLConnectiongetConnection()Get underlying connection static voidsetConnectionFactory(HttpRequest.ConnectionFactory connectionFactory)Specify the ConnectionFactory used to create new requests. static Stringencode(CharSequence url)Encode the given URL as an ASCII StringThis method ensures the path and query segments of the URL are properlyencoded such as ' ' characters being encoded to '%20' or any UTF-8characters that are non-ASCII. static Stringappend(CharSequence url, Map<out Object, out Object> params)Append given map as query parameters to the base URLEach map entry's key will be a parameter name and the value's toString will be the parameter value. static Stringappend(CharSequence url, Array<Object> params)Append given name/value pairs as query parameters to the base URLThe params argument is interpreted as a sequence of name/value pairs so thegiven number of params must be divisible by 2. static HttpRequestget(CharSequence url)Start a 'GET' request to the given URL static HttpRequestget(URL url)Start a 'GET' request to the given URL static HttpRequestget(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)Start a 'GET' request to the given URL along with the query params static HttpRequestget(CharSequence baseUrl, boolean encode, Array<Object> params)Start a 'GET' request to the given URL along with the query params static HttpRequestpost(CharSequence url)Start a 'POST' request to the given URL static HttpRequestpost(URL url)Start a 'POST' request to the given URL static HttpRequestpost(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)Start a 'POST' request to the given URL along with the query params static HttpRequestpost(CharSequence baseUrl, boolean encode, Array<Object> params)Start a 'POST' request to the given URL along with the query params static HttpRequestput(CharSequence url)Start a 'PUT' request to the given URL static HttpRequestput(URL url)Start a 'PUT' request to the given URL static HttpRequestput(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)Start a 'PUT' request to the given URL along with the query params static HttpRequestput(CharSequence baseUrl, boolean encode, Array<Object> params)Start a 'PUT' request to the given URL along with the query params static HttpRequestdelete(CharSequence url)Start a 'DELETE' request to the given URL static HttpRequestdelete(URL url)Start a 'DELETE' request to the given URL static HttpRequestdelete(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)Start a 'DELETE' request to the given URL along with the query params static HttpRequestdelete(CharSequence baseUrl, boolean encode, Array<Object> params)Start a 'DELETE' request to the given URL along with the query params static HttpRequesthead(CharSequence url)Start a 'HEAD' request to the given URL static HttpRequesthead(URL url)Start a 'HEAD' request to the given URL static HttpRequesthead(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)Start a 'HEAD' request to the given URL along with the query params static HttpRequesthead(CharSequence baseUrl, boolean encode, Array<Object> params)Start a 'GET' request to the given URL along with the query params static HttpRequestoptions(CharSequence url)Start an 'OPTIONS' request to the given URL static HttpRequestoptions(URL url)Start an 'OPTIONS' request to the given URL static HttpRequesttrace(CharSequence url)Start a 'TRACE' request to the given URL static HttpRequesttrace(URL url)Start a 'TRACE' request to the given URL static voidkeepAlive(boolean keepAlive)Set the 'http.keepAlive' property to the given value. static voidmaxConnections(int maxConnections)Set the 'http.maxConnections' property to the given value. static voidproxyHost(String host)Set the 'http.proxyHost' and 'https.proxyHost' properties to the given hostvalue. static voidproxyPort(int port)Set the 'http.proxyPort' and 'https.proxyPort' properties to the given portnumber. static voidnonProxyHosts(Array<String> hosts)Set the 'http.nonProxyHosts' property to the given host values. StringtoString()HttpRequestignoreCloseExceptions(boolean ignore)Set whether or not to ignore exceptions that occur from calling closeThe default value of this setting is truebooleanignoreCloseExceptions()Get whether or not exceptions thrown by close areignored intcode()Get the status code of the response HttpRequestcode(AtomicInteger output)Set the value of the given AtomicInteger to the status code of theresponse booleanok()Is the response code a 200 OK? booleancreated()Is the response code a 201 Created? booleannoContent()Is the response code a 204 No Content? booleanserverError()Is the response code a 500 Internal Server Error? booleanbadRequest()Is the response code a 400 Bad Request? booleannotFound()Is the response code a 404 Not Found? booleannotModified()Is the response code a 304 Not Modified? Stringmessage()Get status message of the response HttpRequestdisconnect()Disconnect the connection HttpRequestchunk(int size)Set chunked streaming mode to the given size HttpRequestbufferSize(int size)Set the size used when buffering and copying between streamsThis size is also used for send and receive buffers created for both charand byte arraysThe default buffer size is 8,192 bytes intbufferSize()Get the configured buffer sizeThe default buffer size is 8,192 bytes HttpRequestuncompress(boolean uncompress)Set whether or not the response body should be automatically uncompressedwhen read from. Stringbody(String charset)Get response as String in given character setThis will fall back to using the UTF-8 character set if the given charsetis null Stringbody()Get response as String using character set returned from charset HttpRequestbody(AtomicReference<String> output)Get the response body as a String and set it as the value of thegiven reference. HttpRequestbody(AtomicReference<String> output, String charset)Get the response body as a String and set it as the value of thegiven reference. booleanisBodyEmpty()Is the response body empty? Array<byte>bytes()Get response as byte array BufferedInputStreambuffer()Get response in a buffered stream InputStreamstream()Get stream to response body InputStreamReaderreader(String charset)Get reader to response body using given character set. InputStreamReaderreader()Get reader to response body using the character set returned from charset BufferedReaderbufferedReader(String charset)Get buffered reader to response body using the given character set r andthe configured buffer size BufferedReaderbufferedReader()Get buffered reader to response body using the character set returned from charset and the configured buffer size HttpRequestreceive(File file)Stream response body to file HttpRequestreceive(OutputStream output)Stream response to given output stream HttpRequestreceive(PrintStream output)Stream response to given print stream HttpRequestreceive(Appendable appendable)Receive response into the given appendable HttpRequestreceive(Writer writer)Receive response into the given writer HttpRequestreadTimeout(int timeout)Set read timeout on connection to given value HttpRequestconnectTimeout(int timeout)Set connect timeout on connection to given value HttpRequestheader(String name, String value)Set header name to given value HttpRequestheader(String name, Number value)Set header name to given value HttpRequestheaders(Map<String, String> headers)Set all headers found in given map where the keys are the header names andthe values are the header values HttpRequestheader(Map.Entry<String, String> header)Set header to have given entry's key as the name and value as the value Stringheader(String name)Get a response header Map<String, List<String>>headers()Get all the response headers longdateHeader(String name)Get a date header from the response falling back to returning -1 if theheader is missing or parsing fails longdateHeader(String name, long defaultValue)Get a date header from the response falling back to returning the givendefault value if the header is missing or parsing fails intintHeader(String name)Get an integer header from the response falling back to returning -1 if theheader is missing or parsing fails intintHeader(String name, int defaultValue)Get an integer header value from the response falling back to the givendefault value if the header is missing or if parsing fails Array<String>headers(String name)Get all values of the given header from the response Stringparameter(String headerName, String paramName)Get parameter with given name from header value in response Map<String, String>parameters(String headerName)Get all parameters from header value in responseThis will be all key=value pairs after the first ';' that are separated bya ';' Stringcharset()Get 'charset' parameter from 'Content-Type' response header HttpRequestuserAgent(String userAgent)Set the 'User-Agent' header to given value HttpRequestreferer(String referer)Set the 'Referer' header to given value HttpRequestuseCaches(boolean useCaches)Set value of setUseCaches HttpRequestacceptEncoding(String acceptEncoding)Set the 'Accept-Encoding' header to given value HttpRequestacceptGzipEncoding()Set the 'Accept-Encoding' header to 'gzip' HttpRequestacceptCharset(String acceptCharset)Set the 'Accept-Charset' header to given value StringcontentEncoding()Get the 'Content-Encoding' header from the response Stringserver()Get the 'Server' header from the response longdate()Get the 'Date' header from the response StringcacheControl()Get the 'Cache-Control' header from the response StringeTag()Get the 'ETag' header from the response longexpires()Get the 'Expires' header from the response longlastModified()Get the 'Last-Modified' header from the response Stringlocation()Get the 'Location' header from the response HttpRequestauthorization(String authorization)Set the 'Authorization' header to given value HttpRequestproxyAuthorization(String proxyAuthorization)Set the 'Proxy-Authorization' header to given value HttpRequestbasic(String name, String password)Set the 'Authorization' header to given values in Basic authenticationformat HttpRequestproxyBasic(String name, String password)Set the 'Proxy-Authorization' header to given values in Basic authenticationformat HttpRequestifModifiedSince(long ifModifiedSince)Set the 'If-Modified-Since' request header to the given value HttpRequestifNoneMatch(String ifNoneMatch)Set the 'If-None-Match' request header to the given value HttpRequestcontentType(String contentType)Set the 'Content-Type' request header to the given value HttpRequestcontentType(String contentType, String charset)Set the 'Content-Type' request header to the given value and charset StringcontentType()Get the 'Content-Type' header from the response intcontentLength()Get the 'Content-Length' header from the response HttpRequestcontentLength(String contentLength)Set the 'Content-Length' request header to the given value HttpRequestcontentLength(int contentLength)Set the 'Content-Length' request header to the given value HttpRequestaccept(String accept)Set the 'Accept' header to given value HttpRequestacceptJson()Set the 'Accept' header to 'application/json' HttpRequestprogress(HttpRequest.UploadProgress callback)Set the UploadProgress callback for this request HttpRequestpart(String name, String part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, String part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, String contentType, String part)Write part of a multipart request to the request body HttpRequestpart(String name, Number part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, Number part)Write part of a multipart request to the request body HttpRequestpart(String name, File part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, File part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, String contentType, File part)Write part of a multipart request to the request body HttpRequestpart(String name, InputStream part)Write part of a multipart request to the request body HttpRequestpart(String name, String filename, String contentType, InputStream part)Write part of a multipart request to the request body HttpRequestpartHeader(String name, String value)Write a multipart header to the response body HttpRequestsend(File input)Write contents of file to request body HttpRequestsend(Array<byte> input)Write byte array to request body HttpRequestsend(InputStream input)Write stream to request bodyThe given stream will be closed once sending completes HttpRequestsend(Reader input)Write reader to request bodyThe given reader will be closed once sending completes HttpRequestsend(CharSequence value)Write char sequence to request bodyThe charset configured via contentType will be used andUTF-8 will be used if it is unset. OutputStreamWriterwriter()Create writer to request output stream HttpRequestform(Map<out Object, out Object> values)Write the values in the map as form data to the request bodyThe pairs specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type HttpRequestform(Map.Entry<out Object, out Object> entry)Write the key and value in the entry as form data to the request bodyThe pair specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type HttpRequestform(Map.Entry<out Object, out Object> entry, String charset)Write the key and value in the entry as form data to the request bodyThe pair specified will be URL-encoded and sent with the'application/x-www-form-urlencoded' content-type HttpRequestform(Object name, Object value)Write the name/value pair as form data to the request bodyThe pair specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type HttpRequestform(Object name, Object value, String charset)Write the name/value pair as form data to the request bodyThe values specified will be URL-encoded and sent with the'application/x-www-form-urlencoded' content-type HttpRequestform(Map<out Object, out Object> values, String charset)Write the values in the map as encoded form data to the request body HttpRequesttrustAllCerts(boolean trust)HttpRequesttrustAllCerts()Configure HTTPS connection to trust all certificatesThis method does nothing if the current request is not a HTTPS request HttpRequesttrustAllHosts()Configure HTTPS connection to trust all hosts using a custom HostnameVerifier that always returns truefor eachhost verifiedThis method does nothing if the current request is not a HTTPS requestURLurl()Get the URL of this request's connection Stringmethod()Get the HTTP method of this request HttpRequestuseProxy(String proxyHost, int proxyPort)Configure an HTTP proxy on this connection. HttpRequestfollowRedirects(boolean followRedirects)Set whether or not the underlying connection should follow redirects inthe response. -
-
Constructor Detail
-
HttpRequest
HttpRequest(CharSequence url, String method)
Create HTTP connection wrapper- Parameters:
url- Remote resource URL.method- HTTP request method (e.g., "GET", "POST").
-
-
Method Detail
-
getConnection
HttpURLConnection getConnection()
Get underlying connection
-
setConnectionFactory
static void setConnectionFactory(HttpRequest.ConnectionFactory connectionFactory)
Specify the ConnectionFactory used to create new requests.
-
encode
static String encode(CharSequence url)
Encode the given URL as an ASCII String
This method ensures the path and query segments of the URL are properlyencoded such as ' ' characters being encoded to '%20' or any UTF-8characters that are non-ASCII. No encoding of URLs is done by default bythe HttpRequest constructors and so if URL encoding is needed thismethod should be called before calling the HttpRequest constructor.
-
append
static String append(CharSequence url, Map<out Object, out Object> params)
Append given map as query parameters to the base URL
Each map entry's key will be a parameter name and the value's toString will be the parameter value.
-
append
static String append(CharSequence url, Array<Object> params)
Append given name/value pairs as query parameters to the base URL
The params argument is interpreted as a sequence of name/value pairs so thegiven number of params must be divisible by 2.
- Parameters:
params- name/value pairs
-
get
static HttpRequest get(CharSequence url)
Start a 'GET' request to the given URL
-
get
static HttpRequest get(URL url)
Start a 'GET' request to the given URL
-
get
static HttpRequest get(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)
Start a 'GET' request to the given URL along with the query params
- Parameters:
params- The query parameters to include as part of the baseUrlencode- true to encode the full URL
-
get
static HttpRequest get(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'GET' request to the given URL along with the query params
- Parameters:
encode- true to encode the full URLparams- the name/value query parameter pairs to include as part of thebaseUrl
-
post
static HttpRequest post(CharSequence url)
Start a 'POST' request to the given URL
-
post
static HttpRequest post(URL url)
Start a 'POST' request to the given URL
-
post
static HttpRequest post(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)
Start a 'POST' request to the given URL along with the query params
- Parameters:
params- the query parameters to include as part of the baseUrlencode- true to encode the full URL
-
post
static HttpRequest post(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'POST' request to the given URL along with the query params
- Parameters:
encode- true to encode the full URLparams- the name/value query parameter pairs to include as part of thebaseUrl
-
put
static HttpRequest put(CharSequence url)
Start a 'PUT' request to the given URL
-
put
static HttpRequest put(URL url)
Start a 'PUT' request to the given URL
-
put
static HttpRequest put(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)
Start a 'PUT' request to the given URL along with the query params
- Parameters:
params- the query parameters to include as part of the baseUrlencode- true to encode the full URL
-
put
static HttpRequest put(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'PUT' request to the given URL along with the query params
- Parameters:
encode- true to encode the full URLparams- the name/value query parameter pairs to include as part of thebaseUrl
-
delete
static HttpRequest delete(CharSequence url)
Start a 'DELETE' request to the given URL
-
delete
static HttpRequest delete(URL url)
Start a 'DELETE' request to the given URL
-
delete
static HttpRequest delete(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)
Start a 'DELETE' request to the given URL along with the query params
- Parameters:
params- The query parameters to include as part of the baseUrlencode- true to encode the full URL
-
delete
static HttpRequest delete(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'DELETE' request to the given URL along with the query params
- Parameters:
encode- true to encode the full URLparams- the name/value query parameter pairs to include as part of thebaseUrl
-
head
static HttpRequest head(CharSequence url)
Start a 'HEAD' request to the given URL
-
head
static HttpRequest head(URL url)
Start a 'HEAD' request to the given URL
-
head
static HttpRequest head(CharSequence baseUrl, Map<out Object, out Object> params, boolean encode)
Start a 'HEAD' request to the given URL along with the query params
- Parameters:
params- The query parameters to include as part of the baseUrlencode- true to encode the full URL
-
head
static HttpRequest head(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'GET' request to the given URL along with the query params
- Parameters:
encode- true to encode the full URLparams- the name/value query parameter pairs to include as part of thebaseUrl
-
options
static HttpRequest options(CharSequence url)
Start an 'OPTIONS' request to the given URL
-
options
static HttpRequest options(URL url)
Start an 'OPTIONS' request to the given URL
-
trace
static HttpRequest trace(CharSequence url)
Start a 'TRACE' request to the given URL
-
trace
static HttpRequest trace(URL url)
Start a 'TRACE' request to the given URL
-
keepAlive
static void keepAlive(boolean keepAlive)
Set the 'http.keepAlive' property to the given value.
This setting will apply to all requests.
-
maxConnections
static void maxConnections(int maxConnections)
Set the 'http.maxConnections' property to the given value.
This setting will apply to all requests.
-
proxyHost
static void proxyHost(String host)
Set the 'http.proxyHost' and 'https.proxyHost' properties to the given hostvalue.
This setting will apply to all requests.
-
proxyPort
static void proxyPort(int port)
Set the 'http.proxyPort' and 'https.proxyPort' properties to the given portnumber.
This setting will apply to all requests.
-
nonProxyHosts
static void nonProxyHosts(Array<String> hosts)
Set the 'http.nonProxyHosts' property to the given host values.
Hosts will be separated by a '|' character.
This setting will apply to all requests.
-
ignoreCloseExceptions
HttpRequest ignoreCloseExceptions(boolean ignore)
Set whether or not to ignore exceptions that occur from calling close
The default value of this setting is
true
-
ignoreCloseExceptions
boolean ignoreCloseExceptions()
Get whether or not exceptions thrown by close areignored
-
code
int code()
Get the status code of the response
-
code
HttpRequest code(AtomicInteger output)
Set the value of the given AtomicInteger to the status code of theresponse
-
ok
boolean ok()
Is the response code a 200 OK?
-
created
boolean created()
Is the response code a 201 Created?
-
noContent
boolean noContent()
Is the response code a 204 No Content?
-
serverError
boolean serverError()
Is the response code a 500 Internal Server Error?
-
badRequest
boolean badRequest()
Is the response code a 400 Bad Request?
-
notFound
boolean notFound()
Is the response code a 404 Not Found?
-
notModified
boolean notModified()
Is the response code a 304 Not Modified?
-
disconnect
HttpRequest disconnect()
Disconnect the connection
-
chunk
HttpRequest chunk(int size)
Set chunked streaming mode to the given size
-
bufferSize
HttpRequest bufferSize(int size)
Set the size used when buffering and copying between streams
This size is also used for send and receive buffers created for both charand byte arrays
The default buffer size is 8,192 bytes
-
bufferSize
int bufferSize()
Get the configured buffer size
The default buffer size is 8,192 bytes
-
uncompress
HttpRequest uncompress(boolean uncompress)
Set whether or not the response body should be automatically uncompressedwhen read from.
This will only affect requests that have the 'Content-Encoding' responseheader set to 'gzip'.
This causes all receive methods to use a GZIPInputStream whenapplicable so that higher level streams and readers can read the datauncompressed.
Setting this option does not cause any request headers to be setautomatically so acceptGzipEncoding should be used inconjunction with this setting to tell the server to gzip the response.
-
body
String body(String charset)
Get response as String in given character set
This will fall back to using the UTF-8 character set if the given charsetis null
-
body
HttpRequest body(AtomicReference<String> output)
Get the response body as a String and set it as the value of thegiven reference.
-
body
HttpRequest body(AtomicReference<String> output, String charset)
Get the response body as a String and set it as the value of thegiven reference.
-
isBodyEmpty
boolean isBodyEmpty()
Is the response body empty?
-
buffer
BufferedInputStream buffer()
Get response in a buffered stream
-
stream
InputStream stream()
Get stream to response body
-
reader
InputStreamReader reader(String charset)
Get reader to response body using given character set.
This will fall back to using the UTF-8 character set if the given charsetis null
-
reader
InputStreamReader reader()
Get reader to response body using the character set returned from charset
-
bufferedReader
BufferedReader bufferedReader(String charset)
Get buffered reader to response body using the given character set r andthe configured buffer size
-
bufferedReader
BufferedReader bufferedReader()
Get buffered reader to response body using the character set returned from charset and the configured buffer size
-
receive
HttpRequest receive(File file)
Stream response body to file
-
receive
HttpRequest receive(OutputStream output)
Stream response to given output stream
-
receive
HttpRequest receive(PrintStream output)
Stream response to given print stream
-
receive
HttpRequest receive(Appendable appendable)
Receive response into the given appendable
-
receive
HttpRequest receive(Writer writer)
Receive response into the given writer
-
readTimeout
HttpRequest readTimeout(int timeout)
Set read timeout on connection to given value
-
connectTimeout
HttpRequest connectTimeout(int timeout)
Set connect timeout on connection to given value
-
header
HttpRequest header(String name, String value)
Set header name to given value
-
header
HttpRequest header(String name, Number value)
Set header name to given value
-
headers
HttpRequest headers(Map<String, String> headers)
Set all headers found in given map where the keys are the header names andthe values are the header values
-
header
HttpRequest header(Map.Entry<String, String> header)
Set header to have given entry's key as the name and value as the value
-
dateHeader
long dateHeader(String name)
Get a date header from the response falling back to returning -1 if theheader is missing or parsing fails
-
dateHeader
long dateHeader(String name, long defaultValue)
Get a date header from the response falling back to returning the givendefault value if the header is missing or parsing fails
-
intHeader
int intHeader(String name)
Get an integer header from the response falling back to returning -1 if theheader is missing or parsing fails
-
intHeader
int intHeader(String name, int defaultValue)
Get an integer header value from the response falling back to the givendefault value if the header is missing or if parsing fails
-
parameter
String parameter(String headerName, String paramName)
Get parameter with given name from header value in response
-
parameters
Map<String, String> parameters(String headerName)
Get all parameters from header value in response
This will be all key=value pairs after the first ';' that are separated bya ';'
-
userAgent
HttpRequest userAgent(String userAgent)
Set the 'User-Agent' header to given value
-
referer
HttpRequest referer(String referer)
Set the 'Referer' header to given value
-
useCaches
HttpRequest useCaches(boolean useCaches)
Set value of setUseCaches
-
acceptEncoding
HttpRequest acceptEncoding(String acceptEncoding)
Set the 'Accept-Encoding' header to given value
-
acceptGzipEncoding
HttpRequest acceptGzipEncoding()
Set the 'Accept-Encoding' header to 'gzip'
-
acceptCharset
HttpRequest acceptCharset(String acceptCharset)
Set the 'Accept-Charset' header to given value
-
contentEncoding
String contentEncoding()
Get the 'Content-Encoding' header from the response
-
date
long date()
Get the 'Date' header from the response
-
cacheControl
String cacheControl()
Get the 'Cache-Control' header from the response
-
expires
long expires()
Get the 'Expires' header from the response
-
lastModified
long lastModified()
Get the 'Last-Modified' header from the response
-
authorization
HttpRequest authorization(String authorization)
Set the 'Authorization' header to given value
-
proxyAuthorization
HttpRequest proxyAuthorization(String proxyAuthorization)
Set the 'Proxy-Authorization' header to given value
-
basic
HttpRequest basic(String name, String password)
Set the 'Authorization' header to given values in Basic authenticationformat
-
proxyBasic
HttpRequest proxyBasic(String name, String password)
Set the 'Proxy-Authorization' header to given values in Basic authenticationformat
-
ifModifiedSince
HttpRequest ifModifiedSince(long ifModifiedSince)
Set the 'If-Modified-Since' request header to the given value
-
ifNoneMatch
HttpRequest ifNoneMatch(String ifNoneMatch)
Set the 'If-None-Match' request header to the given value
-
contentType
HttpRequest contentType(String contentType)
Set the 'Content-Type' request header to the given value
-
contentType
HttpRequest contentType(String contentType, String charset)
Set the 'Content-Type' request header to the given value and charset
-
contentType
String contentType()
Get the 'Content-Type' header from the response
-
contentLength
int contentLength()
Get the 'Content-Length' header from the response
-
contentLength
HttpRequest contentLength(String contentLength)
Set the 'Content-Length' request header to the given value
-
contentLength
HttpRequest contentLength(int contentLength)
Set the 'Content-Length' request header to the given value
-
accept
HttpRequest accept(String accept)
Set the 'Accept' header to given value
-
acceptJson
HttpRequest acceptJson()
Set the 'Accept' header to 'application/json'
-
progress
HttpRequest progress(HttpRequest.UploadProgress callback)
Set the UploadProgress callback for this request
-
part
HttpRequest part(String name, String part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, String part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, String contentType, String part)
Write part of a multipart request to the request body
- Parameters:
contentType- value of the Content-Type part header
-
part
HttpRequest part(String name, Number part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, Number part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, File part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, File part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, String contentType, File part)
Write part of a multipart request to the request body
- Parameters:
contentType- value of the Content-Type part header
-
part
HttpRequest part(String name, InputStream part)
Write part of a multipart request to the request body
-
part
HttpRequest part(String name, String filename, String contentType, InputStream part)
Write part of a multipart request to the request body
- Parameters:
contentType- value of the Content-Type part header
-
partHeader
HttpRequest partHeader(String name, String value)
Write a multipart header to the response body
-
send
HttpRequest send(File input)
Write contents of file to request body
-
send
HttpRequest send(Array<byte> input)
Write byte array to request body
-
send
HttpRequest send(InputStream input)
Write stream to request body
The given stream will be closed once sending completes
-
send
HttpRequest send(Reader input)
Write reader to request body
The given reader will be closed once sending completes
-
send
HttpRequest send(CharSequence value)
Write char sequence to request body
The charset configured via contentType will be used andUTF-8 will be used if it is unset.
-
writer
OutputStreamWriter writer()
Create writer to request output stream
-
form
HttpRequest form(Map<out Object, out Object> values)
Write the values in the map as form data to the request body
The pairs specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type
-
form
HttpRequest form(Map.Entry<out Object, out Object> entry)
Write the key and value in the entry as form data to the request body
The pair specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type
-
form
HttpRequest form(Map.Entry<out Object, out Object> entry, String charset)
Write the key and value in the entry as form data to the request body
The pair specified will be URL-encoded and sent with the'application/x-www-form-urlencoded' content-type
-
form
HttpRequest form(Object name, Object value)
Write the name/value pair as form data to the request body
The pair specified will be URL-encoded in UTF-8 and sent with the'application/x-www-form-urlencoded' content-type
-
form
HttpRequest form(Object name, Object value, String charset)
Write the name/value pair as form data to the request body
The values specified will be URL-encoded and sent with the'application/x-www-form-urlencoded' content-type
-
form
HttpRequest form(Map<out Object, out Object> values, String charset)
Write the values in the map as encoded form data to the request body
-
trustAllCerts
HttpRequest trustAllCerts(boolean trust)
-
trustAllCerts
HttpRequest trustAllCerts()
Configure HTTPS connection to trust all certificates
This method does nothing if the current request is not a HTTPS request
-
trustAllHosts
HttpRequest trustAllHosts()
Configure HTTPS connection to trust all hosts using a custom HostnameVerifier that always returns
truefor eachhost verifiedThis method does nothing if the current request is not a HTTPS request
-
useProxy
HttpRequest useProxy(String proxyHost, int proxyPort)
Configure an HTTP proxy on this connection. Use {proxyBasic ifthis proxy requires basic authentication.
-
followRedirects
HttpRequest followRedirects(boolean followRedirects)
Set whether or not the underlying connection should follow redirects inthe response.
- Parameters:
followRedirects- - true fo follow redirects, false to not.
-
-
-
-