org.jsoup.Connection |
Known Indirect Subclasses |
A Connection provides a convenient interface to fetch content from the web, and parse them into Documents.
To get a new Connection, use 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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Connection.Base<T extends Base> | Common methods for Requests and Responses | ||||||||||
Connection.KeyVal | A Key Value tuple. | ||||||||||
Connection.Method | GET and POST http methods. | ||||||||||
Connection.Request | Represents a HTTP request. | ||||||||||
Connection.Response | Represents a HTTP response. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Set a cookie to be sent in the request
| |||||||||||
Add a request data parameter.
| |||||||||||
Add a number of request data parameters.
| |||||||||||
Adds all of the supplied data to the request data parameters
| |||||||||||
Execute the request.
| |||||||||||
Configures the connection to (not) follow server redirects.
| |||||||||||
Execute the request as a GET, and parse the result.
| |||||||||||
Set a request header.
| |||||||||||
Set the request method to use, GET or POST.
| |||||||||||
Execute the request as a POST, and parse the result.
| |||||||||||
Set the request referrer (aka "referer") header.
| |||||||||||
Set the connection's request
| |||||||||||
Get the request object associatated with this connection
| |||||||||||
Set the conenction's response
| |||||||||||
Get the response, once the request has been executed
| |||||||||||
Set the request timeouts (connect and read).
| |||||||||||
Set the request URL to fetch.
| |||||||||||
Set the request URL to fetch.
| |||||||||||
Set the request user-agent header.
|
Set a cookie to be sent in the request
name | name of cookie |
---|---|
value | value of cookie |
Add a request data parameter. Request parameters are sent in the request query string for GETs, and in the request body for POSTs. A request may have multiple values of the same name.
key | data key |
---|---|
value | data value |
Add a number of request data parameters. Multiple parameters may be set at once, e.g.:
.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. |
---|
Adds all of the supplied data to the request data parameters
data | map of data parameters |
---|
Configures the connection to (not) follow server redirects. By default this is true.
followRedirects | true if server redirects should be followed. |
---|
Execute the request as a GET, and parse the result.
IOException | on error |
---|
Set a request header.
name | header name |
---|---|
value | header value |
Set the request method to use, GET or POST. Default is GET.
method | HTTP request method |
---|
Execute the request as a POST, and parse the result.
IOException | on error |
---|
Set the request referrer (aka "referer") header.
referrer | referrer to use |
---|
Set the connection's request
request | new request object |
---|
Get the request object associatated with this connection
Set the conenction's response
response | new response |
---|
Get the response, once the request has been executed
Set the request timeouts (connect and read). If a timeout occurs, an IOException will be thrown. The default timeout is 3 seconds (3000 millis). A timeout of zero is treated as an infinite timeout.
millis | number of milliseconds (thousandths of a second) before timing out connects or reads. |
---|
Set the request URL to fetch. The protocol must be HTTP or HTTPS.
url | URL to connect to |
---|
Set the request URL to fetch. The protocol must be HTTP or HTTPS.
url | URL to connect to |
---|
Set the request user-agent header.
userAgent | user-agent to use |
---|