|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Connection
A Connection provides a convenient interface to fetch content from the web, and parse them into Documents.
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.
Nested Class Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
Document |
get()
Execute the request as a GET, and parse the result. |
Connection |
header(String name,
String value)
Set a request header. |
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. |
Method Detail |
---|
Connection url(URL url)
url
- URL to connect to
Connection url(String url)
url
- URL to connect to
Connection userAgent(String userAgent)
userAgent
- user-agent to use
Connection timeout(int millis)
millis
- number of milliseconds (thousandths of a second) before timing out connects or reads.
Connection referrer(String referrer)
referrer
- referrer to use
Connection method(Connection.Method method)
method
- HTTP request method
Connection data(String key, String value)
key
- data keyvalue
- data value
Connection data(Map<String,String> data)
data
- map of data parameters
Connection 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 value
Connection.Base.headers()
Connection cookie(String name, String value)
name
- name of cookievalue
- value of cookie
Document 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 object
Connection.Response response()
Connection response(Connection.Response response)
response
- new response
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |