Package org.jsoup
Interface Connection.Response
- All Superinterfaces:
Connection.Base<Connection.Response>
- All Known Implementing Classes:
HttpConnection.Response
- Enclosing interface:
- Connection
public static interface Connection.Response extends Connection.Base<Connection.Response>
Represents a HTTP response.
-
Method Summary
Modifier and Type Method Description String
body()
Get the body of the response as a plain string.byte[]
bodyAsBytes()
Get the body of the response as an array of bytes.BufferedInputStream
bodyStream()
Get the body of the response as a (buffered) InputStream.Connection.Response
bufferUp()
Read the body of the response into a local buffer, so thatparse()
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).String
charset()
Get the character set name of the response, derived from the content-type header.Connection.Response
charset(String charset)
Set / override the response character set.String
contentType()
Get the response content type (e.g.Document
parse()
Read and parse the body of the response as a Document.int
statusCode()
Get the status code of the response.String
statusMessage()
Get the status message of the response.Methods 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
int statusCode()Get the status code of the response.- Returns:
- status code
-
statusMessage
String statusMessage()Get the status message of the response.- Returns:
- status message
-
charset
Get the character set name of the response, derived from the content-type header.- Returns:
- character set name if set, null if not
-
charset
Set / override the response character set. When the document body is parsed it will be with this charset.- Parameters:
charset
- to decode body as- Returns:
- this Response, for chaining
-
contentType
Get the response content type (e.g. "text/html");- Returns:
- the response content type, or null if one was not set
-
parse
Read and parse the body of the response as a Document. If you intend to parse the same response multiple times, you shouldbufferUp()
first.- Returns:
- a parsed Document
- Throws:
IOException
- on error
-
body
String body()Get the body of the response as a plain string.- Returns:
- body
-
bodyAsBytes
byte[] bodyAsBytes()Get the body of the response as an array of bytes.- Returns:
- body bytes
-
bufferUp
Connection.Response bufferUp()Read the body of the response into a local buffer, so thatparse()
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). Callingbody()
orbodyAsBytes()
has the same effect.- Returns:
- this response, for chaining
- Throws:
UncheckedIOException
- if an IO exception occurs during buffering.
-
bodyStream
BufferedInputStream bodyStream()Get 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 bufferUp, body, parse, etc) will not work in conjunction with this method.This method is useful for writing large responses to disk, without buffering them completely into memory first.
- Returns:
- the response body input stream
-