public class

HttpConnection

extends Object
implements Connection
java.lang.Object
   ↳ org.jsoup.helper.HttpConnection

Class Overview

Implementation of Connection.

See Also

Summary

Nested Classes
class HttpConnection.KeyVal  
class HttpConnection.Request  
class HttpConnection.Response  
Public Methods
static Connection connect(URL url)
static Connection connect(String url)
Connection cookie(String name, String value)
Set a cookie to be sent in the request
Connection data(String key, String value)
Add a request data parameter.
Connection data(String... keyvals)
Add a number of request data parameters.
Connection data(Map<StringString> data)
Adds all of the supplied data to the request data parameters
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 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(Connection.Request request)
Set the connection's request
Connection.Request request()
Get the request object associatated with this connection
Connection response(Connection.Response response)
Set the conenction's response
Connection.Response response()
Get the response, once the request has been executed
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.jsoup.Connection

Public Methods

public static Connection connect (URL url)

public static Connection connect (String url)

public Connection cookie (String name, String value)

Set a cookie to be sent in the request

Parameters
name name of cookie
value value of cookie
Returns
  • this Connection, for chaining

public Connection data (String key, String value)

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.

Parameters
key data key
value data value
Returns
  • this Connection, for chaining

public Connection data (String... keyvals)

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

Parameters
keyvals a set of key value pairs.
Returns
  • this Connection, for chaining

public Connection data (Map<StringString> data)

Adds all of the supplied data to the request data parameters

Parameters
data map of data parameters
Returns
  • this Connection, for chaining

public Connection.Response execute ()

Execute the request.

Returns
  • a response object
Throws
IOException

public Connection followRedirects (boolean followRedirects)

Configures the connection to (not) follow server redirects. By default this is true.

Parameters
followRedirects true if server redirects should be followed.
Returns
  • this Connection, for chaining

public Document get ()

Execute the request as a GET, and parse the result.

Returns
  • parsed Document
Throws
IOException

public Connection header (String name, String value)

Set a request header.

Parameters
name header name
value header value
Returns
  • this Connection, for chaining

public Connection method (Connection.Method method)

Set the request method to use, GET or POST. Default is GET.

Parameters
method HTTP request method
Returns
  • this Connection, for chaining

public Document post ()

Execute the request as a POST, and parse the result.

Returns
  • parsed Document
Throws
IOException

public Connection referrer (String referrer)

Set the request referrer (aka "referer") header.

Parameters
referrer referrer to use
Returns
  • this Connection, for chaining

public Connection request (Connection.Request request)

Set the connection's request

Parameters
request new request object
Returns
  • this Connection, for chaining

public Connection.Request request ()

Get the request object associatated with this connection

Returns
  • request

public Connection response (Connection.Response response)

Set the conenction's response

Parameters
response new response
Returns
  • this Connection, for chaining

public Connection.Response response ()

Get the response, once the request has been executed

Returns
  • response

public Connection timeout (int millis)

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.

Parameters
millis number of milliseconds (thousandths of a second) before timing out connects or reads.
Returns
  • this Connection, for chaining

public Connection url (String url)

Set the request URL to fetch. The protocol must be HTTP or HTTPS.

Parameters
url URL to connect to
Returns
  • this Connection, for chaining

public Connection url (URL url)

Set the request URL to fetch. The protocol must be HTTP or HTTPS.

Parameters
url URL to connect to
Returns
  • this Connection, for chaining

public Connection userAgent (String userAgent)

Set the request user-agent header.

Parameters
userAgent user-agent to use
Returns
  • this Connection, for chaining