- All Implemented Interfaces:
Serializable
- Author:
- Brad Clarke, Hans Donner, Ahmed Ashour, Marc Guillemot, Rodney Gitzel, Ronald Brill, Adam Afeltowicz, Joerg Werner, Michael Lueck, Lai Quang Duong, Kristof Neirynck
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe destination of a request, as defined by the Fetch spec ( https://fetch.spec.whatwg.org/#concept-request-destination).static enumThe mode of a request, as defined by the Fetch spec ( https://fetch.spec.whatwg.org/#concept-request-mode).static enumEnum to configure request creation. -
Constructor Summary
ConstructorsConstructorDescriptionWebRequest(URL url) Creates or updates this object..WebRequest(URL url, String acceptHeader, String acceptEncodingHeader) Creates or updates this object..WebRequest(URL url, Charset charset, URL refererUrl) Creates or updates this object..WebRequest(URL url, HttpMethod submitMethod) Creates or updates this object.. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHint(WebRequest.HttpHint hint) Creates or updates this object..getAdditionalHeader(String name) Creates or updates this object..Returns the additional HTTP headers to use.Returns the character set to use to perform the request.org.apache.http.auth.CredentialsReturns the credentials if set from the external builder.Returns the default character set to use for the response when it does not specify one.Returns the form encoding type to use.Returns the destination of this request, used to compute theSec-Fetch-Destheader (and, unless overridden, the defaultSec-Fetch-Mode).Returns the explicit mode override for this request, if any.Returns the HTTP submit method to use.Returns the request parameters to use.Returns the proxy host to use.intReturns the proxy port to use.Returns the proxy scheme to use.Returns the body content to be submitted if this is aPOSTrequest.Returns the URL of the document or script that initiated this request, used to compute theSec-Fetch-Siteheader.Returns the request parameters to use.intReturns the timeout to use.getUrl()Returns the target URL.org.apache.http.auth.CredentialsReturns the credentials if set as part of the url.booleanhasHint(WebRequest.HttpHint hint) Creates or updates this object..booleanisAdditionalHeader(String name) Creates or updates this object..booleanReturns whether SOCKS proxy or not.booleanReturns whether this request is the result of a navigation backed by genuine user activation (e.g. a click on a link, a typed URL, or a form submitted via a click on its submit button) as opposed to one triggered purely by script (e.g.voidmarkAsNavigation(URL requestingUrl, boolean userActivation) Convenience method for the common case of a top-level navigation (an anchor/area click, a form submission, a script-driven location change, ...): setsWebRequest.FetchDestination.DOCUMENT, the initiator URL, and whether the navigation was backed by genuine user activation, all in one call.voidmarkAsNavigation(WebRequest.FetchDestination destination, URL requestingUrl, boolean userActivation) Same asmarkAsNavigation(URL, boolean), but for navigations whose destination isn't a top-levelWebRequest.FetchDestination.DOCUMENT- currently only<iframe>/<frame>loads (WebRequest.FetchDestination.IFRAME/WebRequest.FetchDestination.FRAME).static WebRequestReturns a new request for about:blank.voidremoveAdditionalHeader(String name) Creates or updates this object..voidsetAdditionalHeader(String name, String value) Creates or updates this object..voidsetAdditionalHeaders(Map<String, String> additionalHeaders) Creates or updates this object..voidsetCharset(Charset charset) Creates or updates this object.voidsetCredentials(org.apache.http.auth.Credentials credentials) Creates or updates this object..voidsetDefaultResponseContentCharset(Charset defaultResponseContentCharset) Creates or updates this object.voidsetEncodingType(FormEncodingType encodingType) Creates or updates this object..voidsetFetchDestination(WebRequest.FetchDestination fetchDestination) Sets the destination of this request.voidsetFetchModeOverride(WebRequest.FetchMode fetchMode) Sets an explicit mode override for this request, e.g. for afetch()call using an explicitmodeoption, or a subresource request using thecrossoriginattribute (which forces CORS mode).voidsetHttpMethod(HttpMethod submitMethod) Creates or updates this object..voidsetProxyHost(String proxyHost) Creates or updates this object.voidsetProxyPort(int proxyPort) Creates or updates this object.voidsetProxyScheme(String proxyScheme) Creates or updates this object..voidsetRefererHeader(URL url) Creates or updates this object..voidsetRequestBody(String requestBody) Creates or updates this object..voidsetRequestingUrl(URL requestingUrl) Sets the URL of the document or script that initiated this request.voidsetRequestParameters(List<NameValuePair> requestParameters) Creates or updates this object..voidsetSocksProxy(boolean isSocksProxy) Creates or updates this object..voidsetTimeout(int timeout) Creates or updates this object..voidCreates or updates this object.voidsetUserActivation(boolean userActivation) Sets whether this request is the result of a navigation backed by genuine user activation.toString()Returns a string representation of this object.
-
Constructor Details
-
WebRequest
Creates or updates this object.. Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URLacceptHeader- the accept header to useacceptEncodingHeader- the accept encoding header to use
-
WebRequest
Creates or updates this object.. Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URLcharset- the charset to userefererUrl- the url be used by the referer header
-
WebRequest
Creates or updates this object.. Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URL
-
WebRequest
Creates or updates this object.. Instantiates aWebRequestfor the specified URL using the specified HTTP submit method.- Parameters:
url- the target URLsubmitMethod- the HTTP submit method to use
-
-
Method Details
-
newAboutBlankRequest
Returns a new request for about:blank.- Returns:
- a new request for about:blank
-
getUrl
Returns the target URL. Returns the target URL.- Returns:
- the target URL
-
setUrl
Creates or updates this object. Sets the target URL. The URL may be simplified if needed (for instance eliminating irrelevant path portions like "/./").- Parameters:
url- the target URL
-
getProxyHost
Returns the proxy host to use. Returns the proxy host to use.- Returns:
- the proxy host to use
-
setProxyHost
Creates or updates this object. Sets the proxy host to use.- Parameters:
proxyHost- the proxy host to use
-
getProxyPort
public int getProxyPort()Returns the proxy port to use. Returns the proxy port to use.- Returns:
- the proxy port to use
-
setProxyPort
public void setProxyPort(int proxyPort) Creates or updates this object. Sets the proxy port to use.- Parameters:
proxyPort- the proxy port to use
-
getProxyScheme
Returns the proxy scheme to use. Returns the proxy scheme to use.- Returns:
- the proxy scheme to use
-
setProxyScheme
Creates or updates this object.. Sets the proxy scheme to use.- Parameters:
proxyScheme- the proxy scheme to use
-
isSocksProxy
public boolean isSocksProxy()Returns whether SOCKS proxy or not. Returns whether SOCKS proxy or not.- Returns:
- whether SOCKS proxy or not
-
setSocksProxy
public void setSocksProxy(boolean isSocksProxy) Creates or updates this object.. Sets whether SOCKS proxy or not.- Parameters:
isSocksProxy- whether SOCKS proxy or not
-
getTimeout
public int getTimeout()Returns the timeout to use.- Returns:
- the timeout to use
-
setTimeout
public void setTimeout(int timeout) Creates or updates this object.. Sets the timeout to use.- Parameters:
timeout- the timeout to use
-
getEncodingType
Returns the form encoding type to use. Returns the form encoding type to use.- Returns:
- the form encoding type to use
-
setEncodingType
Creates or updates this object.. Sets the form encoding type to use.- Parameters:
encodingType- the form encoding type to use
-
getParameters
Returns the request parameters to use.Retrieves the request parameters used. Similar to the servlet api function getParameterMap() this works depending on the request type and collects the url parameters and the body stuff.
The value is also normalized - null is converted to an empty string.In contrast to the servlet api this creates a separate KeyValuePair for every parameter. This means that pairs with the same name can be part of the list. The servlet api will return a string[] as value for the key in this case.
Additionally this method includes also the uploaded files for multipart post requests.- Returns:
- the request parameters to use
-
getRequestParameters
Returns the request parameters to use. INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Retrieves the request parameters to use. If set, these request parameters will overwrite any request parameters which may be present in theURL. Should not be used in combination with therequest body.- Returns:
- the request parameters to use
-
setRequestParameters
Creates or updates this object.. INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the request parameters to use. If set, these request parameters will overwrite any request parameters which may be present in theURL. Should not be used in combination with therequest body.- Parameters:
requestParameters- the request parameters to use- Throws:
RuntimeException- if the request body has already been set
-
getRequestBody
Returns the body content to be submitted if this is aPOSTrequest. Returns the body content to be submitted if this is aPOSTrequest. Ignored for all other request types. Should not be used in combination withrequest parameters.- Returns:
- the body content to be submitted if this is a
POSTrequest
-
setRequestBody
Creates or updates this object.. Sets the body content to be submitted if this is aPOST,PUTorPATCHrequest. Other request types result inRuntimeException. Should not be used in combination withrequest parameters.- Parameters:
requestBody- the body content to be submitted if this is aPOST,PUTorPATCHrequest- Throws:
RuntimeException- if the request parameters have already been set or this is not aPOST,PUTorPATCHrequest.
-
getHttpMethod
Returns the HTTP submit method to use. Returns the HTTP submit method to use.- Returns:
- the HTTP submit method to use
-
setHttpMethod
Creates or updates this object.. Sets the HTTP submit method to use.- Parameters:
submitMethod- the HTTP submit method to use
-
getAdditionalHeaders
Returns the additional HTTP headers to use. Returns the additional HTTP headers to use.- Returns:
- the additional HTTP headers to use
-
setAdditionalHeaders
Creates or updates this object.. Sets the additional HTTP headers to use.- Parameters:
additionalHeaders- the additional HTTP headers to use
-
isAdditionalHeader
Creates or updates this object.. Returns whether the specified header name is already included in the additional HTTP headers.- Parameters:
name- the name of the additional HTTP header- Returns:
- true if the specified header name is included in the additional HTTP headers
-
getAdditionalHeader
Creates or updates this object.. Returns the header value associated with this name.- Parameters:
name- the name of the additional HTTP header- Returns:
- the value or null
-
setRefererHeader
Creates or updates this object.. Sets the referer HTTP header - only if the provided url is valid.- Parameters:
url- the url for the referer HTTP header
-
getFetchDestination
Returns the destination of this request, used to compute theSec-Fetch-Destheader (and, unless overridden, the defaultSec-Fetch-Mode). Defaults toWebRequest.FetchDestination.EMPTY, which is correct for plainXMLHttpRequest/fetch()calls.- Returns:
- the destination of this request
-
setFetchDestination
Sets the destination of this request.- Parameters:
fetchDestination- the destination of this request, ornullto reset toWebRequest.FetchDestination.EMPTY
-
getFetchModeOverride
Returns the explicit mode override for this request, if any. Whennull(the default), the mode is derived from thedestination.- Returns:
- the mode override, or
nullif none was set
-
setFetchModeOverride
Sets an explicit mode override for this request, e.g. for afetch()call using an explicitmodeoption, or a subresource request using thecrossoriginattribute (which forces CORS mode).- Parameters:
fetchMode- the mode to use, ornullto derive it from thedestination
-
isUserActivation
public boolean isUserActivation()Returns whether this request is the result of a navigation backed by genuine user activation (e.g. a click on a link, a typed URL, or a form submitted via a click on its submit button) as opposed to one triggered purely by script (e.g.location.href = ..., a<meta http-equiv="refresh">, or an automatically-loaded<iframe>).Only relevant for requests whose
Sec-Fetch-Modeisnavigate; used to compute the presence of theSec-Fetch-Userheader, which real browsers omit entirely (never send as?0) whenever this isfalse.- Returns:
- whether this request was triggered by a real user gesture
-
setUserActivation
public void setUserActivation(boolean userActivation) Sets whether this request is the result of a navigation backed by genuine user activation.- Parameters:
userActivation- whether this request was triggered by a real user gesture
-
getRequestingUrl
Returns the URL of the document or script that initiated this request, used to compute theSec-Fetch-Siteheader.nullmeans there is no initiator (e.g. a browser-chrome-initiated navigation such as a typed URL or bookmark), which maps toSec-Fetch-Site: none.Note this is tracked separately from the
Refererheader: unlike the referrer, it must not be affected by referrer-policy stripping, sinceSec-Fetch-Sitealways reflects the true relationship between the initiator and the target, even when noRefererheader is sent.- Returns:
- the URL of the initiator, or
nullif there is none
-
setRequestingUrl
Sets the URL of the document or script that initiated this request.- Parameters:
requestingUrl- the URL of the initiator, ornullif there is none
-
setAdditionalHeader
Creates or updates this object.. Sets the specified name/value pair in the additional HTTP headers.- Parameters:
name- the name of the additional HTTP headervalue- the value of the additional HTTP header
-
removeAdditionalHeader
Creates or updates this object.. Removed the specified name/value pair from the additional HTTP headers.- Parameters:
name- the name of the additional HTTP header
-
getUrlCredentials
public org.apache.http.auth.Credentials getUrlCredentials()Returns the credentials if set as part of the url. Returns the credentials to use.- Returns:
- the credentials if set as part of the url
-
getCredentials
public org.apache.http.auth.Credentials getCredentials()Returns the credentials if set from the external builder. Returns the credentials to use.- Returns:
- the credentials if set from the external builder
-
setCredentials
public void setCredentials(org.apache.http.auth.Credentials credentials) Creates or updates this object.. Sets the credentials to use.- Parameters:
credentials- the credentials to use
-
getCharset
Returns the character set to use to perform the request. Returns the character set to use to perform the request.- Returns:
- the character set to use to perform the request
-
setCharset
Creates or updates this object. Sets the character set to use to perform the request. The default value isStandardCharsets.ISO_8859_1.- Parameters:
charset- the character set to use to perform the request
-
getDefaultResponseContentCharset
Returns the default character set to use for the response when it does not specify one.- Returns:
- the default character set to use for the response when it does not specify one.
-
setDefaultResponseContentCharset
Creates or updates this object. Sets the default character set to use for the response when it does not specify one.Unless set, the default is
StandardCharsets.UTF_8.- Parameters:
defaultResponseContentCharset- the default character set of the response
-
hasHint
Creates or updates this object..- Parameters:
hint- the hint to check for- Returns:
- true if the hint is enabled
-
addHint
Creates or updates this object.. Enables the hint.- Parameters:
hint- the hint to add
-
toString
Returns a string representation of this object. Returns a string representation of this object.
-