public interface Connection
To get a new Connection, use Jsoup.connect(String)
. Connections contain Connection.Request
and Connection.Response
objects. The request objects are reusable as prototype requests.
Request configuration can be made using either the shortcut methods in Connection (e.g. userAgent(String)
),
or by methods in the Connection.Request object directly. All request configuration must be made before the request
is executed.
The Connection interface is currently in beta and subject to change. Comments, suggestions, and bug reports are welcome.
Modifier and Type | Interface and Description |
---|---|
static interface |
Connection.Base<T extends Connection.Base>
Common methods for Requests and Responses
|
static interface |
Connection.KeyVal
A Key Value tuple.
|
static class |
Connection.Method
GET and POST http methods.
|
static interface |
Connection.Request
Represents a HTTP request.
|
static interface |
Connection.Response
Represents a HTTP response.
|
Modifier and Type | Method and Description |
---|---|
Connection |
cookie(String name,
String value)
Set a cookie to be sent in the request
|
Connection |
data(Map<String,String> data)
Adds all of the supplied data to the request data parameters
|
Connection |
data(String... keyvals)
Add a number of request data parameters.
|
Connection |
data(String key,
String value)
Add a request data parameter.
|
Connection.Response |
execute()
Execute the request.
|
Connection |
followRedirects(boolean followRedirects)
Configures the connection to (not) follow server redirects.
|
Document |
get()
Execute the request as a GET, and parse the result.
|
Connection |
header(String name,
String value)
Set a request header.
|
Connection |
ignoreContentType(boolean ignoreContentType)
Ignore the document's Content-Type when parsing the response.
|
Connection |
ignoreHttpErrors(boolean ignoreHttpErrors)
Configures the connection to not throw exceptions when a HTTP error occurs.
|
Connection |
method(Connection.Method method)
Set the request method to use, GET or POST.
|
Document |
post()
Execute the request as a POST, and parse the result.
|
Connection |
referrer(String referrer)
Set the request referrer (aka "referer") header.
|
Connection.Request |
request()
Get the request object associatated with this connection
|
Connection |
request(Connection.Request request)
Set the connection's request
|
Connection.Response |
response()
Get the response, once the request has been executed
|
Connection |
response(Connection.Response response)
Set the conenction's response
|
Connection |
timeout(int millis)
Set the request timeouts (connect and read).
|
Connection |
url(String url)
Set the request URL to fetch.
|
Connection |
url(URL url)
Set the request URL to fetch.
|
Connection |
userAgent(String userAgent)
Set the request user-agent header.
|
Connection url(URL url)
url
- URL to connect toConnection url(String url)
url
- URL to connect toConnection userAgent(String userAgent)
userAgent
- user-agent to useConnection timeout(int millis)
millis
- number of milliseconds (thousandths of a second) before timing out connects or reads.Connection referrer(String referrer)
referrer
- referrer to useConnection followRedirects(boolean followRedirects)
followRedirects
- true if server redirects should be followed.Connection method(Connection.Method method)
method
- HTTP request methodConnection ignoreHttpErrors(boolean ignoreHttpErrors)
ignoreHttpErrors
- - false (default) if HTTP errors should be ignored.Connection ignoreContentType(boolean ignoreContentType)
ignoreContentType
- set to true if you would like the content type ignored on parsing the response into a
Document.Connection data(String key, String value)
key
- data keyvalue
- data valueConnection data(Map<String,String> data)
data
- map of data parametersConnection data(String... keyvals)
.data("name", "jsoup", "language", "Java", "language", "English");
creates a query string like:
?name=jsoup&language=Java&language=English
keyvals
- a set of key value pairs.Connection header(String name, String value)
name
- header namevalue
- header valueConnection.Base.headers()
Connection cookie(String name, String value)
name
- name of cookievalue
- value of cookieDocument get() throws IOException
IOException
- on errorDocument post() throws IOException
IOException
- on errorConnection.Response execute() throws IOException
IOException
- on errorConnection.Request request()
Connection request(Connection.Request request)
request
- new request objectConnection.Response response()
Connection response(Connection.Response response)
response
- new responseCopyright © 2009-2015 Jonathan Hedley. All Rights Reserved.