-
public class HttpRequest
A 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 interface
HttpRequest.ConnectionFactory
Creates HTTP connections for urls.
public interface
HttpRequest.UploadProgress
Callback interface for reporting upload progress for a request.
public class
HttpRequest.Base64
Encodes 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 class
HttpRequest.HttpRequestException
HTTP request exception whose cause is always an IOException
public class
HttpRequest.RequestOutputStream
Request output stream
-
Field Summary
Fields Modifier and Type Field Description public final static String
CHARSET_UTF8
public final static String
CONTENT_TYPE_FORM
public final static String
CONTENT_TYPE_JSON
public final static String
ENCODING_GZIP
public final static String
HEADER_ACCEPT
public final static String
HEADER_ACCEPT_CHARSET
public final static String
HEADER_ACCEPT_ENCODING
public final static String
HEADER_AUTHORIZATION
public final static String
HEADER_CACHE_CONTROL
public final static String
HEADER_CONTENT_ENCODING
public final static String
HEADER_CONTENT_LENGTH
public final static String
HEADER_CONTENT_TYPE
public final static String
HEADER_DATE
public final static String
HEADER_ETAG
public final static String
HEADER_EXPIRES
public final static String
HEADER_IF_NONE_MATCH
public final static String
HEADER_LAST_MODIFIED
public final static String
HEADER_LOCATION
public final static String
HEADER_PROXY_AUTHORIZATION
public final static String
HEADER_REFERER
public final static String
HEADER_SERVER
public final static String
HEADER_USER_AGENT
public final static String
METHOD_DELETE
public final static String
METHOD_GET
public final static String
METHOD_HEAD
public final static String
METHOD_OPTIONS
public final static String
METHOD_POST
public final static String
METHOD_PUT
public final static String
METHOD_TRACE
public final static String
PARAM_CHARSET
private HttpURLConnection
connection
-
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 HttpURLConnection
getConnection()
Get underlying connection static void
setConnectionFactory(HttpRequest.ConnectionFactory connectionFactory)
Specify the ConnectionFactory used to create new requests. static String
encode(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 String
append(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 String
append(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 HttpRequest
get(CharSequence url)
Start a 'GET' request to the given URL static HttpRequest
get(URL url)
Start a 'GET' request to the given URL 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 static HttpRequest
get(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'GET' request to the given URL along with the query params static HttpRequest
post(CharSequence url)
Start a 'POST' request to the given URL static HttpRequest
post(URL url)
Start a 'POST' request to the given URL 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 static HttpRequest
post(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'POST' request to the given URL along with the query params static HttpRequest
put(CharSequence url)
Start a 'PUT' request to the given URL static HttpRequest
put(URL url)
Start a 'PUT' request to the given URL 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 static HttpRequest
put(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'PUT' request to the given URL along with the query params static HttpRequest
delete(CharSequence url)
Start a 'DELETE' request to the given URL static HttpRequest
delete(URL url)
Start a 'DELETE' request to the given URL 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 static HttpRequest
delete(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'DELETE' request to the given URL along with the query params static HttpRequest
head(CharSequence url)
Start a 'HEAD' request to the given URL static HttpRequest
head(URL url)
Start a 'HEAD' request to the given URL 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 static HttpRequest
head(CharSequence baseUrl, boolean encode, Array<Object> params)
Start a 'GET' request to the given URL along with the query params static HttpRequest
options(CharSequence url)
Start an 'OPTIONS' request to the given URL static HttpRequest
options(URL url)
Start an 'OPTIONS' request to the given URL static HttpRequest
trace(CharSequence url)
Start a 'TRACE' request to the given URL static HttpRequest
trace(URL url)
Start a 'TRACE' request to the given URL static void
keepAlive(boolean keepAlive)
Set the 'http.keepAlive' property to the given value. static void
maxConnections(int maxConnections)
Set the 'http.maxConnections' property to the given value. static void
proxyHost(String host)
Set the 'http.proxyHost' and 'https.proxyHost' properties to the given hostvalue. static void
proxyPort(int port)
Set the 'http.proxyPort' and 'https.proxyPort' properties to the given portnumber. static void
nonProxyHosts(Array<String> hosts)
Set the 'http.nonProxyHosts' property to the given host values. String
toString()
HttpRequest
ignoreCloseExceptions(boolean ignore)
Set whether or not to ignore exceptions that occur from calling closeThe default value of this setting is true
boolean
ignoreCloseExceptions()
Get whether or not exceptions thrown by close areignored int
code()
Get the status code of the response HttpRequest
code(AtomicInteger output)
Set the value of the given AtomicInteger to the status code of theresponse boolean
ok()
Is the response code a 200 OK? boolean
created()
Is the response code a 201 Created? boolean
noContent()
Is the response code a 204 No Content? boolean
serverError()
Is the response code a 500 Internal Server Error? boolean
badRequest()
Is the response code a 400 Bad Request? boolean
notFound()
Is the response code a 404 Not Found? boolean
notModified()
Is the response code a 304 Not Modified? String
message()
Get status message of the response HttpRequest
disconnect()
Disconnect the connection HttpRequest
chunk(int size)
Set chunked streaming mode to the given size HttpRequest
bufferSize(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 int
bufferSize()
Get the configured buffer sizeThe default buffer size is 8,192 bytes HttpRequest
uncompress(boolean uncompress)
Set whether or not the response body should be automatically uncompressedwhen read from. String
body(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 String
body()
Get response as String using character set returned from charset HttpRequest
body(AtomicReference<String> output)
Get the response body as a String and set it as the value of thegiven reference. HttpRequest
body(AtomicReference<String> output, String charset)
Get the response body as a String and set it as the value of thegiven reference. boolean
isBodyEmpty()
Is the response body empty? Array<byte>
bytes()
Get response as byte array BufferedInputStream
buffer()
Get response in a buffered stream InputStream
stream()
Get stream to response body InputStreamReader
reader(String charset)
Get reader to response body using given character set. InputStreamReader
reader()
Get reader to response body using the character set returned from charset BufferedReader
bufferedReader(String charset)
Get buffered reader to response body using the given character set r andthe configured buffer size BufferedReader
bufferedReader()
Get buffered reader to response body using the character set returned from charset and the configured buffer size HttpRequest
receive(File file)
Stream response body to file HttpRequest
receive(OutputStream output)
Stream response to given output stream HttpRequest
receive(PrintStream output)
Stream response to given print stream HttpRequest
receive(Appendable appendable)
Receive response into the given appendable HttpRequest
receive(Writer writer)
Receive response into the given writer HttpRequest
readTimeout(int timeout)
Set read timeout on connection to given value HttpRequest
connectTimeout(int timeout)
Set connect timeout on connection to given value HttpRequest
header(String name, String value)
Set header name to given value HttpRequest
header(String name, Number value)
Set header name to given value 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 HttpRequest
header(Map.Entry<String, String> header)
Set header to have given entry's key as the name and value as the value String
header(String name)
Get a response header Map<String, List<String>>
headers()
Get all the response headers long
dateHeader(String name)
Get a date header from the response falling back to returning -1 if theheader is missing or parsing fails 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 int
intHeader(String name)
Get an integer header from the response falling back to returning -1 if theheader is missing or parsing fails 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 Array<String>
headers(String name)
Get all values of the given header from the response String
parameter(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 ';' String
charset()
Get 'charset' parameter from 'Content-Type' response header HttpRequest
userAgent(String userAgent)
Set the 'User-Agent' header to given value HttpRequest
referer(String referer)
Set the 'Referer' header to given value HttpRequest
useCaches(boolean useCaches)
Set value of setUseCaches HttpRequest
acceptEncoding(String acceptEncoding)
Set the 'Accept-Encoding' header to given value HttpRequest
acceptGzipEncoding()
Set the 'Accept-Encoding' header to 'gzip' HttpRequest
acceptCharset(String acceptCharset)
Set the 'Accept-Charset' header to given value String
contentEncoding()
Get the 'Content-Encoding' header from the response String
server()
Get the 'Server' header from the response long
date()
Get the 'Date' header from the response String
cacheControl()
Get the 'Cache-Control' header from the response String
eTag()
Get the 'ETag' header from the response long
expires()
Get the 'Expires' header from the response long
lastModified()
Get the 'Last-Modified' header from the response String
location()
Get the 'Location' header from the response HttpRequest
authorization(String authorization)
Set the 'Authorization' header to given value HttpRequest
proxyAuthorization(String proxyAuthorization)
Set the 'Proxy-Authorization' header to given value HttpRequest
basic(String name, String password)
Set the 'Authorization' header to given values in Basic authenticationformat HttpRequest
proxyBasic(String name, String password)
Set the 'Proxy-Authorization' header to given values in Basic authenticationformat HttpRequest
ifModifiedSince(long ifModifiedSince)
Set the 'If-Modified-Since' request header to the given value HttpRequest
ifNoneMatch(String ifNoneMatch)
Set the 'If-None-Match' request header to the given value HttpRequest
contentType(String contentType)
Set the 'Content-Type' request header to the given value HttpRequest
contentType(String contentType, String charset)
Set the 'Content-Type' request header to the given value and charset String
contentType()
Get the 'Content-Type' header from the response int
contentLength()
Get the 'Content-Length' header from the response HttpRequest
contentLength(String contentLength)
Set the 'Content-Length' request header to the given value HttpRequest
contentLength(int contentLength)
Set the 'Content-Length' request header to the given value HttpRequest
accept(String accept)
Set the 'Accept' header to given value HttpRequest
acceptJson()
Set the 'Accept' header to 'application/json' HttpRequest
progress(HttpRequest.UploadProgress callback)
Set the UploadProgress callback for this request HttpRequest
part(String name, String part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, String part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, String contentType, String part)
Write part of a multipart request to the request body HttpRequest
part(String name, Number part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, Number part)
Write part of a multipart request to the request body HttpRequest
part(String name, File part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, File part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, String contentType, File part)
Write part of a multipart request to the request body HttpRequest
part(String name, InputStream part)
Write part of a multipart request to the request body HttpRequest
part(String name, String filename, String contentType, InputStream part)
Write part of a multipart request to the request body HttpRequest
partHeader(String name, String value)
Write a multipart header to the response body HttpRequest
send(File input)
Write contents of file to request body HttpRequest
send(Array<byte> input)
Write byte array to request body HttpRequest
send(InputStream input)
Write stream to request bodyThe given stream will be closed once sending completes HttpRequest
send(Reader input)
Write reader to request bodyThe given reader will be closed once sending completes HttpRequest
send(CharSequence value)
Write char sequence to request bodyThe charset configured via contentType will be used andUTF-8 will be used if it is unset. OutputStreamWriter
writer()
Create writer to request output stream HttpRequest
form(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 HttpRequest
form(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 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 bodyThe pair specified will be URL-encoded and sent with the'application/x-www-form-urlencoded' content-type HttpRequest
form(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 HttpRequest
form(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 HttpRequest
form(Map<out Object, out Object> values, String charset)
Write the values in the map as encoded form data to the request body HttpRequest
trustAllCerts(boolean trust)
HttpRequest
trustAllCerts()
Configure HTTPS connection to trust all certificatesThis method does nothing if the current request is not a HTTPS request HttpRequest
trustAllHosts()
Configure HTTPS connection to trust all hosts using a custom HostnameVerifier that always returns true
for eachhost verifiedThis method does nothing if the current request is not a HTTPS requestURL
url()
Get the URL of this request's connection String
method()
Get the HTTP method of this request HttpRequest
useProxy(String proxyHost, int proxyPort)
Configure an HTTP proxy on this connection. HttpRequest
followRedirects(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
true
for 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.
-
-
-
-