Class HttpConnection.Request
- All Implemented Interfaces:
Connection.Base<Connection.Request>,Connection.Request
- Enclosing class:
- HttpConnection
-
Method Summary
Modifier and TypeMethodDescriptionAdd a header.@Nullable RequestAuthenticatorauth()Get the RequestAuthenticator, if any, that will be used on this request.auth(@Nullable RequestAuthenticator authenticator) Set the authenticator to use for this request.Get a cookie value by name from this request/response.Set a cookie in this request/response.cookies()Retrieve the request/response cookies as a map.data()Get all of the request's data parametersdata(Connection.KeyVal keyval) Add a data parameter to the requestbooleanGet the current followRedirects configuration.followRedirects(boolean followRedirects) Configures the request to (not) follow server redirects.booleanCheck if a cookie is presentbooleanCheck if a header is presentbooleanhasHeaderWithValue(String name, String value) Test if the request has a header with this value (case-insensitive).@Nullable StringGet the value of a header.Set a header.headers()Retrieve all of the request/response header names and corresponding values as a map.Get the values of a header.booleanGet the current ignoreContentType configuration.ignoreContentType(boolean ignoreContentType) Configures the request to ignore the Content-Type of the response.booleanGet the current ignoreHttpErrors configuration.ignoreHttpErrors(boolean ignoreHttpErrors) Configures the request to ignore HTTP errors in the response.intGet the maximum body size, in bytes.maxBodySize(int bytes) Update the maximum body size, in bytes.method()Get the request method, which defaults toGETmethod(Connection.Method method) Set the request methodRetreive all of the headers, keyed by the header name, and with a list of values per header.parser()Get the current parser to use when parsing the document.Specify the parser to use when parsing the document.Gets the post data character set for x-www-form-urlencoded post datapostDataCharset(String charset) Sets the post data character set for x-www-form-urlencoded post data@Nullable Proxyproxy()Get the proxy used for this request.Update the proxy for this request.Set the HTTP proxy to use for this request.removeCookie(String name) Remove a cookie by nameremoveHeader(String name) Remove headers by name.@Nullable StringGet the current request body.requestBody(@Nullable String body) Set a POST (or PUT) request body.requestBodyStream(InputStream stream) Set the request body.@Nullable SSLContextGet the current custom SSL context, if any.sslContext(SSLContext sslContext) Set a custom SSL context for HTTPS connections.@Nullable SSLSocketFactoryGet the current custom SSL socket factory, if any.voidsslSocketFactory(SSLSocketFactory sslSocketFactory) Set a custom SSL socket factory for HTTPS connections.inttimeout()Get the request timeout, in milliseconds.timeout(int millis) Update the request timeout.url()Get the URL of this Request or Response.Set the URLMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
-
proxy
Description copied from interface:Connection.RequestGet the proxy used for this request.- Specified by:
proxyin interfaceConnection.Request- Returns:
- the proxy;
nullif not enabled.
-
proxy
Description copied from interface:Connection.RequestUpdate the proxy for this request.- Specified by:
proxyin interfaceConnection.Request- Parameters:
proxy- the proxy ot use;nullto disable.- Returns:
- this Request, for chaining
-
proxy
Description copied from interface:Connection.RequestSet the HTTP proxy to use for this request.- Specified by:
proxyin interfaceConnection.Request- Parameters:
host- the proxy hostnameport- the proxy port- Returns:
- this Connection, for chaining
-
timeout
Description copied from interface:Connection.RequestGet the request timeout, in milliseconds.- Specified by:
timeoutin interfaceConnection.Request- Returns:
- the timeout in milliseconds.
-
timeout
Description copied from interface:Connection.RequestUpdate the request timeout.- Specified by:
timeoutin interfaceConnection.Request- Parameters:
millis- timeout, in milliseconds- Returns:
- this Request, for chaining
-
maxBodySize
Description copied from interface:Connection.RequestGet the maximum body size, in bytes.- Specified by:
maxBodySizein interfaceConnection.Request- Returns:
- the maximum body size, in bytes.
-
maxBodySize
Description copied from interface:Connection.RequestUpdate the maximum body size, in bytes.- Specified by:
maxBodySizein interfaceConnection.Request- Parameters:
bytes- maximum body size, in bytes.- Returns:
- this Request, for chaining
-
followRedirects
Description copied from interface:Connection.RequestGet the current followRedirects configuration.- Specified by:
followRedirectsin interfaceConnection.Request- Returns:
- true if followRedirects is enabled.
-
followRedirects
Description copied from interface:Connection.RequestConfigures the request to (not) follow server redirects. By default this is true.- Specified by:
followRedirectsin interfaceConnection.Request- Parameters:
followRedirects- true if server redirects should be followed.- Returns:
- this Request, for chaining
-
ignoreHttpErrors
Description copied from interface:Connection.RequestGet the current ignoreHttpErrors configuration.- Specified by:
ignoreHttpErrorsin interfaceConnection.Request- Returns:
- true if errors will be ignored; false (default) if HTTP errors will cause an IOException to be thrown.
-
sslSocketFactory
Description copied from interface:Connection.RequestGet the current custom SSL socket factory, if any.- Specified by:
sslSocketFactoryin interfaceConnection.Request- Returns:
- custom SSL socket factory if set, null otherwise
-
sslSocketFactory
Description copied from interface:Connection.RequestSet a custom SSL socket factory for HTTPS connections.Note: if set, the legacy
HttpURLConnectionwill be used instead of the JVM'sHttpClient.- Specified by:
sslSocketFactoryin interfaceConnection.Request- Parameters:
sslSocketFactory- SSL socket factory- See Also:
-
sslContext
Description copied from interface:Connection.RequestGet the current custom SSL context, if any.- Specified by:
sslContextin interfaceConnection.Request- Returns:
- custom SSL context if set, null otherwise
-
sslContext
Description copied from interface:Connection.RequestSet a custom SSL context for HTTPS connections.Note: when using the legacy
HttpURLConnection, only theSSLSocketFactoryfrom the context will be used.- Specified by:
sslContextin interfaceConnection.Request- Parameters:
sslContext- SSL context- Returns:
- this Request, for chaining
-
ignoreHttpErrors
Description copied from interface:Connection.RequestConfigures the request to ignore HTTP errors in the response.- Specified by:
ignoreHttpErrorsin interfaceConnection.Request- Parameters:
ignoreHttpErrors- set to true to ignore HTTP errors.- Returns:
- this Request, for chaining
-
ignoreContentType
Description copied from interface:Connection.RequestGet the current ignoreContentType configuration.- Specified by:
ignoreContentTypein interfaceConnection.Request- Returns:
- true if invalid content-types will be ignored; false (default) if they will cause an IOException to be thrown.
-
ignoreContentType
Description copied from interface:Connection.RequestConfigures the request to ignore the Content-Type of the response.- Specified by:
ignoreContentTypein interfaceConnection.Request- Parameters:
ignoreContentType- set to true to ignore the content type.- Returns:
- this Request, for chaining
-
data
Description copied from interface:Connection.RequestAdd a data parameter to the request- Specified by:
datain interfaceConnection.Request- Parameters:
keyval- data to add.- Returns:
- this Request, for chaining
-
data
Description copied from interface:Connection.RequestGet all of the request's data parameters- Specified by:
datain interfaceConnection.Request- Returns:
- collection of keyvals
-
requestBody
Description copied from interface:Connection.RequestSet a POST (or PUT) request body. Useful when a server expects a plain request body, not a set of URL encoded form key/value pairs. E.g.:Jsoup.connect(url) .requestBody(json) .header("Content-Type", "application/json") .post();If any data key/vals are supplied, they will be sent as URL query params.
- Specified by:
requestBodyin interfaceConnection.Request- Parameters:
body- to use as the request body. Set to null to clear a previously set body.- Returns:
- this Request, for chaining
- See Also:
-
requestBody
Description copied from interface:Connection.RequestGet the current request body.- Specified by:
requestBodyin interfaceConnection.Request- Returns:
- null if not set.
-
requestBodyStream
Description copied from interface:Connection.RequestSet the request body. Useful for posting data such as byte arrays or files, and the server expects a single request body (and not a multipart upload). E.g.:Jsoup.connect(url) .requestBody(new ByteArrayInputStream(bytes)) .header("Content-Type", "application/octet-stream") .post();Or, use a FileInputStream to data from disk.
You should close the stream in a finally block.
- Specified by:
requestBodyStreamin interfaceConnection.Request- Parameters:
stream- the input stream to send.- Returns:
- this Request, for chaining
- See Also:
-
parser
Description copied from interface:Connection.RequestSpecify the parser to use when parsing the document.- Specified by:
parserin interfaceConnection.Request- Parameters:
parser- parser to use.- Returns:
- this Request, for chaining
-
parser
Description copied from interface:Connection.RequestGet the current parser to use when parsing the document.- Specified by:
parserin interfaceConnection.Request- Returns:
- current Parser
-
postDataCharset
Description copied from interface:Connection.RequestSets the post data character set for x-www-form-urlencoded post data- Specified by:
postDataCharsetin interfaceConnection.Request- Parameters:
charset- character set to encode post data- Returns:
- this Request, for chaining
-
postDataCharset
Description copied from interface:Connection.RequestGets the post data character set for x-www-form-urlencoded post data- Specified by:
postDataCharsetin interfaceConnection.Request- Returns:
- character set to encode post data
-
auth
Description copied from interface:Connection.RequestSet the authenticator to use for this request. SeeConnection.auth(authenticator)for examples and implementation notes.- Specified by:
authin interfaceConnection.Request- Parameters:
authenticator- the authenticator- Returns:
- this Request, for chaining.
-
auth
Description copied from interface:Connection.RequestGet the RequestAuthenticator, if any, that will be used on this request.- Specified by:
authin interfaceConnection.Request- Returns:
- the RequestAuthenticator, or
nullif not set
-
url
Description copied from interface:Connection.BaseGet the URL of this Request or Response. For redirected responses, this will be the final destination URL.- Specified by:
urlin interfaceConnection.Base<T extends Connection.Base<T>>- Returns:
- URL
-
url
Description copied from interface:Connection.BaseSet the URL- Specified by:
urlin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
url- new URL- Returns:
- this, for chaining
-
method
Description copied from interface:Connection.BaseGet the request method, which defaults toGET- Specified by:
methodin interfaceConnection.Base<T extends Connection.Base<T>>- Returns:
- method
-
method
Description copied from interface:Connection.BaseSet the request method- Specified by:
methodin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
method- new method- Returns:
- this, for chaining
-
header
Description copied from interface:Connection.BaseGet the value of a header. If there is more than one header value with the same name, the headers are returned comma separated, per rfc2616-sec4.Header names are case-insensitive.
- Specified by:
headerin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of header (case-insensitive)- Returns:
- value of header, or null if not set.
- See Also:
-
addHeader
Description copied from interface:Connection.BaseAdd a header. The header will be added regardless of whether a header with the same name already exists.For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, then it should be encoded first per RFC 2047.
- Specified by:
addHeaderin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- Name of new headervalue- Value of new header- Returns:
- this, for chaining
-
headers
Description copied from interface:Connection.BaseGet the values of a header.- Specified by:
headersin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- header name, case-insensitive.- Returns:
- a list of values for this header, or an empty list if not set.
-
header
Description copied from interface:Connection.BaseSet a header. This method will overwrite any existing header with the same case-insensitive name. If there is more than one value for this header, this method will update the first matching header.For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, then it should be encoded first per RFC 2047.
- Specified by:
headerin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- Name of headervalue- Value of header- Returns:
- this, for chaining
- See Also:
-
hasHeader
Description copied from interface:Connection.BaseCheck if a header is present- Specified by:
hasHeaderin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of header (case-insensitive)- Returns:
- if the header is present in this request/response
-
hasHeaderWithValue
Test if the request has a header with this value (case-insensitive).- Specified by:
hasHeaderWithValuein interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- header name (case-insensitive)value- value (case-insensitive)- Returns:
- if the header and value pair are set in this req/res
-
removeHeader
Description copied from interface:Connection.BaseRemove headers by name. If there is more than one header with this name, they will all be removed.- Specified by:
removeHeaderin interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of header to remove (case-insensitive)- Returns:
- this, for chaining
-
headers
Description copied from interface:Connection.BaseRetrieve all of the request/response header names and corresponding values as a map. For headers with multiple values, only the first header is returned.Note that this is a view of the headers only, and changes made to this map will not be reflected in the request/response object.
- Specified by:
headersin interfaceConnection.Base<T extends Connection.Base<T>>- Returns:
- headers
- See Also:
-
multiHeaders
Description copied from interface:Connection.BaseRetreive all of the headers, keyed by the header name, and with a list of values per header.- Specified by:
multiHeadersin interfaceConnection.Base<T extends Connection.Base<T>>- Returns:
- a list of multiple values per header.
-
cookie
Description copied from interface:Connection.BaseGet a cookie value by name from this request/response.- Specified by:
cookiein interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of cookie to retrieve.- Returns:
- value of cookie, or null if not set
-
cookie
Description copied from interface:Connection.BaseSet a cookie in this request/response.- Specified by:
cookiein interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of cookievalue- value of cookie- Returns:
- this, for chaining
-
hasCookie
Description copied from interface:Connection.BaseCheck if a cookie is present- Specified by:
hasCookiein interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of cookie- Returns:
- if the cookie is present in this request/response
-
removeCookie
Description copied from interface:Connection.BaseRemove a cookie by name- Specified by:
removeCookiein interfaceConnection.Base<T extends Connection.Base<T>>- Parameters:
name- name of cookie to remove- Returns:
- this, for chaining
-
cookies
Description copied from interface:Connection.BaseRetrieve the request/response cookies as a map. For response cookies, if duplicate cookie names were sent, the last one set will be the one included. For session management, rather than using these response cookies, prefer to useJsoup.newSession()and related methods.- Specified by:
cookiesin interfaceConnection.Base<T extends Connection.Base<T>>- Returns:
- simple cookie map
- See Also:
-