java.lang.Object
org.htmlunit.WebRequest
- All Implemented Interfaces:
Serializable
Parameter object for making web requests.
- 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 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 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 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.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..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..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.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
-
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.
-