Class HttpConnection.Response
- All Implemented Interfaces:
-
Connection.Base<Connection.Response>,Connection.Response
- Enclosing class:
-
HttpConnection
-
Method Summary
Modifier and TypeMethodDescriptionaddHeader(String name, @Nullable String value) Add a header.Stringbody()Get the body of the response as a plain String.byte[]Get the body of the response as an array of bytes.Get the body of the response as a (buffered) InputStream.bufferUp()Read the body of the response into a local buffer, so thatConnection.Response.parse(may be called repeatedly on the same connection response.) @Nullable Stringcharset()Get the character set name of the response, derived from the content-type header.charset(String charset) Set / override the response character set.@Nullable StringGet the response content type (e.g.Stringcookie(String name) Get a cookie value by name from this request/response.cookie(String name, String value) Set a cookie in this request/response.Map<String, String> cookies()Retrieve the request/response cookies as a map.booleanhasCookie(String name) Check if a cookie is presentbooleanhasHeader(String name) Check if a header is presentbooleanhasHeaderWithValue(String name, String value) Test if the request has a header with this value (case-insensitive).@Nullable Stringheader(String name) Get the value of a header.header(String name, String value) Set a header.Map<String, String> headers()Retrieve all of the request/response header names and corresponding values as a map.List<String> headers(String name) Get the values of a header.method()Get the request method, which defaults toGETmethod(Connection.Method method) Set the request methodMap<String, List<String>> Retreive all of the headers, keyed by the header name, and with a list of values per header.parse()Read and parse the body of the response as a Document.StringreadBody()Read the response body, and returns it as a plain String.Reads the bodyStream into byteData.removeCookie(String name) Remove a cookie by nameremoveHeader(String name) Remove headers by name.intGet the status code of the response.StringGet the status message of the response.Returns aStreamParserthat will parse the Response progressively.url()Get the URL of this Request or Response.Set the URLMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jsoup.Connection.Base
addHeader, cookie, cookie, cookies, hasCookie, hasHeader, hasHeaderWithValue, header, header, headers, headers, method, method, multiHeaders, removeCookie, removeHeader, url, url
-
Method Details
-
statusCode
public int statusCode()Description copied from interface:Connection.ResponseGet the status code of the response.- Specified by:
-
statusCodein interfaceConnection.Response - Returns:
- status code
-
statusMessage
public String statusMessage()Description copied from interface:Connection.ResponseGet the status message of the response.- Specified by:
-
statusMessagein interfaceConnection.Response - Returns:
- status message
-
charset
public @Nullable String charset()Description copied from interface:Connection.ResponseGet the character set name of the response, derived from the content-type header.- Specified by:
-
charsetin interfaceConnection.Response - Returns:
- character set name if set, null if not
-
charset
Description copied from interface:Connection.ResponseSet / override the response character set. When the document body is parsed it will be with this charset.- Specified by:
-
charsetin interfaceConnection.Response - Parameters:
-
charset- to decode body as - Returns:
- this Response, for chaining
-
contentType
public @Nullable String contentType()Description copied from interface:Connection.ResponseGet the response content type (e.g. "text/html");- Specified by:
-
contentTypein interfaceConnection.Response - Returns:
- the response content type, or null if one was not set
-
parse
Description copied from interface:Connection.ResponseRead and parse the body of the response as a Document. If you intend to parse the same response multiple times, you shouldConnection.Response.readFully(first, which will buffer the body into memory.) - Specified by:
-
parsein interfaceConnection.Response - Returns:
- a parsed Document
- Throws:
-
IOException- if an IO exception occurs whilst reading the body. - See Also:
-
streamParser
Description copied from interface:Connection.ResponseReturns aStreamParserthat will parse the Response progressively.- Specified by:
-
streamParserin interfaceConnection.Response - Returns:
- a StreamParser, prepared to parse this response.
- Throws:
-
IOException- if an IO exception occurs preparing the parser.
-
readFully
Reads the bodyStream into byteData. A no-op if already executed.- Specified by:
-
readFullyin interfaceConnection.Response - Returns:
- this response, for chaining
- Throws:
-
IOException- if an IO exception occurs during buffering.
-
readBody
Description copied from interface:Connection.ResponseRead the response body, and returns it as a plain String.- Specified by:
-
readBodyin interfaceConnection.Response - Returns:
- body
- Throws:
-
IOException- if an IO exception occurs whilst reading the body.
-
body
public String body()Description copied from interface:Connection.ResponseGet the body of the response as a plain String.Will throw an UncheckedIOException if the body has not been buffered and an error occurs whilst reading the body; use
Connection.Response.readFully(first to buffer the body and catch any exceptions explicitly. Or more simply,) Connection.Response.readBody(.) - Specified by:
-
bodyin interfaceConnection.Response - Returns:
- body
- See Also:
-
bodyAsBytes
public byte[] bodyAsBytes()Description copied from interface:Connection.ResponseGet the body of the response as an array of bytes.Will throw an UncheckedIOException if the body has not been buffered and an error occurs whilst reading the body; use
Connection.Response.readFully(first to buffer the body and catch any exceptions explicitly.) - Specified by:
-
bodyAsBytesin interfaceConnection.Response - Returns:
- body bytes
- See Also:
-
bufferUp
Description copied from interface:Connection.ResponseRead the body of the response into a local buffer, so thatConnection.Response.parse(may be called repeatedly on the same connection response. Otherwise, once the response is read, its InputStream will have been drained and may not be re-read.) Calling
Connection.Response.body(or) Connection.Response.bodyAsBytes(has the same effect.) - Specified by:
-
bufferUpin interfaceConnection.Response - Returns:
- this response, for chaining
-
bodyStream
Description copied from interface:Connection.ResponseGet the body of the response as a (buffered) InputStream. You should close the input stream when you're done with it.Other body methods (like readFully, body, parse, etc) will generally not work in conjunction with this method, as it consumes the InputStream.
Any configured max size or maximum read timeout applied to the connection will not be applied to this stream, unless
Connection.Response.readFully(is called prior.) This method is useful for writing large responses to disk, without buffering them completely into memory first.
- Specified by:
-
bodyStreamin interfaceConnection.Response - Returns:
- the response body input stream
-
url
Description copied from interface:Connection.BaseGet the URL of this Request or Response. For redirected responses, this will be the final destination URL.- Specified by:
-
urlin interfaceConnection.Base<T extends Connection.Base<T>> - Returns:
- URL
-
url
Description copied from interface:Connection.BaseSet the URL- Specified by:
-
urlin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
url- new URL - Returns:
- this, for chaining
-
method
Description copied from interface:Connection.BaseGet the request method, which defaults toGET- Specified by:
-
methodin interfaceConnection.Base<T extends Connection.Base<T>> - Returns:
- method
-
method
Description copied from interface:Connection.BaseSet the request method- Specified by:
-
methodin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
method- new method - Returns:
- this, for chaining
-
header
public @Nullable String header(String name) Description copied from interface:Connection.BaseGet the value of a header. If there is more than one header value with the same name, the headers are returned comma separated, per rfc2616-sec4.Header names are case-insensitive.
- Specified by:
-
headerin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of header (case-insensitive) - Returns:
- value of header, or null if not set.
- See Also:
-
addHeader
Description copied from interface:Connection.BaseAdd a header. The header will be added regardless of whether a header with the same name already exists.For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, then it should be encoded first per RFC 2047.
- Specified by:
-
addHeaderin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- Name of new header -
value- Value of new header - Returns:
- this, for chaining
-
headers
public List<String> headers(String name) Description copied from interface:Connection.BaseGet the values of a header.- Specified by:
-
headersin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- header name, case-insensitive. - Returns:
- a list of values for this header, or an empty list if not set.
-
header
Description copied from interface:Connection.BaseSet a header. This method will overwrite any existing header with the same case-insensitive name. If there is more than one value for this header, this method will update the first matching header.For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, then it should be encoded first per RFC 2047.
- Specified by:
-
headerin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- Name of header -
value- Value of header - Returns:
- this, for chaining
- See Also:
-
hasHeader
public boolean hasHeader(String name) Description copied from interface:Connection.BaseCheck if a header is present- Specified by:
-
hasHeaderin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of header (case-insensitive) - Returns:
- if the header is present in this request/response
-
hasHeaderWithValue
public boolean hasHeaderWithValue(String name, String value) Test if the request has a header with this value (case-insensitive).- Specified by:
-
hasHeaderWithValuein interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- header name (case-insensitive) -
value- value (case-insensitive) - Returns:
- if the header and value pair are set in this req/res
-
removeHeader
Description copied from interface:Connection.BaseRemove headers by name. If there is more than one header with this name, they will all be removed.- Specified by:
-
removeHeaderin interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of header to remove (case-insensitive) - Returns:
- this, for chaining
-
headers
public Map<String,String> headers()Description copied from interface:Connection.BaseRetrieve all of the request/response header names and corresponding values as a map. For headers with multiple values, only the first header is returned.Note that this is a view of the headers only, and changes made to this map will not be reflected in the request/response object.
- Specified by:
-
headersin interfaceConnection.Base<T extends Connection.Base<T>> - Returns:
- headers
- See Also:
-
multiHeaders
public Map<String,List<String>> multiHeaders()Description copied from interface:Connection.BaseRetreive all of the headers, keyed by the header name, and with a list of values per header.- Specified by:
-
multiHeadersin interfaceConnection.Base<T extends Connection.Base<T>> - Returns:
- a list of multiple values per header.
-
cookie
public String cookie(String name) Description copied from interface:Connection.BaseGet a cookie value by name from this request/response.- Specified by:
-
cookiein interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of cookie to retrieve. - Returns:
- value of cookie, or null if not set
-
cookie
Description copied from interface:Connection.BaseSet a cookie in this request/response.- Specified by:
-
cookiein interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of cookie -
value- value of cookie - Returns:
- this, for chaining
-
hasCookie
public boolean hasCookie(String name) Description copied from interface:Connection.BaseCheck if a cookie is present- Specified by:
-
hasCookiein interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of cookie - Returns:
- if the cookie is present in this request/response
-
removeCookie
Description copied from interface:Connection.BaseRemove a cookie by name- Specified by:
-
removeCookiein interfaceConnection.Base<T extends Connection.Base<T>> - Parameters:
-
name- name of cookie to remove - Returns:
- this, for chaining
-
cookies
public Map<String,String> cookies()Description copied from interface:Connection.BaseRetrieve the request/response cookies as a map. For response cookies, if duplicate cookie names were sent, the last one set will be the one included. For session management, rather than using these response cookies, prefer to useJsoup.newSession(and related methods.) - Specified by:
-
cookiesin interfaceConnection.Base<T extends Connection.Base<T>> - Returns:
- simple cookie map
- See Also:
-