HttpResponse
instance. You can use the response for various stuff: read the statusCode()
or statusPhrase()
; or any header attribute.bodyRaw()
- raw body content, always in ISO-8859-1
encoding.bodyText()
- body text, i.e. string encoded as specified by Content-Type
header.bodyBytes()
- returns the raw body as a byte array, so e.g. downloaded filebodyText()
is one set in the response headers. If the response does not specify the encoding in its headers (but e.g. only on the HTML page), you must specify the encoding with charset()
the method before calling bodyText()
. {: .attn}query()
method:query()
for each parameter, or pass many arguments in one call (varargs). You can also provide Map<String, String>
as a parameter too.removeQuery
to remove some parameters or overloaded methods to replace a parameter.form()
in the same way as query()
to specify form parameters. Everything that is said for query()
applies to the form()
.HttpProgressListener
like this:HttpProgressListener
calculates the callbackSize
- the size of the chunk in bytes that will be transferred. By default, this size equals 1%
of the total size. Moreover, it is never less than 512
bytes.HttpProgressListener
contains the inner field size
with the total size of the request. Note that this is the size of the whole request, not only the files! This is the actual number of bytes that are going to be sent, and it is always a bit larger than file size (due to protocol overhead).header()
. Some common header parameters are already defined as methods, so you will find contentType()
etc.contentTypeJson()
- specifies JSON content typeacceptJson()
- accepts JSON content.unzip()
the response.unzip()
method is safe; it will not fail if the response is not zipped.form()
parameters. body()
method always returns the raw string (encoded as ISO-8859-1). To get the string in usable form, use the method bodyText()
. This method uses a provided charset from the "Content-Type" header and encodes the body string.HttpRequest
does not follow redirection response. This can be changed by setting the followRedirects(true)
. Now redirect responses are followed. When redirection is enabled, the original URL will NOT be preserved in the request object!send()
is called, the program blocks until the response is received. By using sendAsync()
the execution of the sending is passed to Javas fork-join pool, and will be executed asynchronously. Method returns CompletableFuture<Response>
.