Package org.htmlunit
Class WebRequest
java.lang.Object
org.htmlunit.WebRequest
- All Implemented Interfaces:
Serializable
Parameter object for making web requests.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Charsetprivate org.apache.http.auth.Credentialsprivate Charsetprivate static final Patternprivate static final Patternprivate FormEncodingTypeprivate Set<WebRequest.HttpHint> private HttpMethodprivate booleanprivate Stringprivate intprivate Stringprivate static final Patternprivate Stringprivate List<NameValuePair> private intprivate Stringprivate org.apache.http.auth.Credentials -
Constructor Summary
ConstructorsConstructorDescriptionWebRequest(URL url) Instantiates aWebRequestfor the specified URL.WebRequest(URL url, String acceptHeader, String acceptEncodingHeader) Instantiates aWebRequestfor the specified URL.WebRequest(URL url, Charset charset, URL refererUrl) Instantiates aWebRequestfor the specified URL.WebRequest(URL url, HttpMethod submitMethod) Instantiates aWebRequestfor the specified URL using the specified HTTP submit method. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHint(WebRequest.HttpHint hint) private static URLbuildUrlWithNewPath(URL url, String newPath) getAdditionalHeader(String name) Returns the header value associated with this name.Returns the additional HTTP headers to use.Returns the character set to use to perform the request.org.apache.http.auth.CredentialsReturns the credentials to use.Returns the form encoding type to use.Returns the HTTP submit method to use.Retrieves the request parameters in 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.INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Retrieves the request parameters to use.intgetUrl()Returns the target URL.org.apache.http.auth.CredentialsReturns the credentials to use.booleanhasHint(WebRequest.HttpHint hint) booleanisAdditionalHeader(String name) Returns whether the specified header name is already included in the additional HTTP headers.booleanReturns whether SOCKS proxy or not.static WebRequestprivate static List<NameValuePair> normalize(List<NameValuePair> pairs) private voidvoidremoveAdditionalHeader(String name) Removed the specified name/value pair from the additional HTTP headers.private static StringremoveDots(String path) voidsetAdditionalHeader(String name, String value) Sets the specified name/value pair in the additional HTTP headers.voidsetAdditionalHeaders(Map<String, String> additionalHeaders) Sets the additional HTTP headers to use.voidsetCharset(Charset charset) Sets the character set to use to perform the request.voidsetCredentials(org.apache.http.auth.Credentials credentials) Sets the credentials to use.voidsetDefaultResponseContentCharset(Charset defaultResponseContentCharset) Sets the default character set to use for the response when it does not specify one.voidsetEncodingType(FormEncodingType encodingType) Sets the form encoding type to use.voidsetHttpMethod(HttpMethod submitMethod) Sets the HTTP submit method to use.voidsetProxyHost(String proxyHost) Sets the proxy host to use.voidsetProxyPort(int proxyPort) Sets the proxy port to use.voidsetProxyScheme(String proxyScheme) Sets the proxy scheme to use.voidsetRefererlHeader(URL url) Sets the referer HTTP header - only if the provided url is valid.voidsetRequestBody(String requestBody) Sets the body content to be submitted if this is aPOST,PUTorPATCHrequest.voidsetRequestParameters(List<NameValuePair> requestParameters) INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the request parameters to use.voidsetSocksProxy(boolean isSocksProxy) Sets whether SOCKS proxy or not.voidsetTimeout(int timeout) Sets the timeout to use.voidSets the target URL.toString()Returns a string representation of this object.private void
-
Field Details
-
DOT_PATTERN
-
DOT_DOT_PATTERN
-
REMOVE_DOTS_PATTERN
-
url_
-
proxyHost_
-
proxyPort_
private int proxyPort_ -
proxyScheme_
-
isSocksProxy_
private boolean isSocksProxy_ -
httpMethod_
-
encodingType_
-
additionalHeaders_
-
urlCredentials_
private org.apache.http.auth.Credentials urlCredentials_ -
credentials_
private org.apache.http.auth.Credentials credentials_ -
timeout_
private int timeout_ -
httpHints_
-
charset_
-
defaultResponseContentCharset_
-
requestParameters_
-
requestBody_
-
-
Constructor Details
-
WebRequest
Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URLacceptHeader- the accept header to useacceptEncodingHeader- the accept encoding header to use
-
WebRequest
Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URLcharset- the charset to userefererUrl- the url be used by the referer header
-
WebRequest
Instantiates aWebRequestfor the specified URL.- Parameters:
url- the target URL
-
WebRequest
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
-
getUrl
Returns the target URL.- Returns:
- the target URL
-
setUrl
Sets the target URL. The URL may be simplified if needed (for instance eliminating irrelevant path portions like "/./").- Parameters:
url- the target URL
-
removeDots
-
buildUrlWithNewPath
-
getProxyHost
Returns the proxy host to use.- Returns:
- the proxy host to use
-
setProxyHost
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
-
setProxyPort
public void setProxyPort(int proxyPort) 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
-
setProxyScheme
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
-
setSocksProxy
public void setSocksProxy(boolean isSocksProxy) Sets whether SOCKS proxy or not.- Parameters:
isSocksProxy- whether SOCKS proxy or not
-
getTimeout
public int getTimeout()- Returns:
- the timeout to use
-
setTimeout
public void setTimeout(int timeout) 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
-
setEncodingType
Sets the form encoding type to use.- Parameters:
encodingType- the form encoding type to use
-
getParameters
Retrieves the request parameters in use. Similar to the servlet api this will work depending on the request type and check the url parameters and the body. The value is also normalized - null is converted to an empty string.- Returns:
- the request parameters to use
-
normalize
-
getRequestParameters
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
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. 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
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
-
setHttpMethod
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
-
setAdditionalHeaders
Sets the additional HTTP headers to use.- Parameters:
additionalHeaders- the additional HTTP headers to use
-
isAdditionalHeader
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
Returns the header value associated with this name.- Parameters:
name- the name of the additional HTTP header- Returns:
- the value or null
-
setRefererlHeader
Sets the referer HTTP header - only if the provided url is valid.- Parameters:
url- the url for the referer HTTP header
-
setAdditionalHeader
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
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 to use.- Returns:
- the credentials if set as part of the url
-
getCredentials
public org.apache.http.auth.Credentials getCredentials()Returns the credentials to use.- Returns:
- the credentials if set from the external builder
-
setCredentials
public void setCredentials(org.apache.http.auth.Credentials credentials) 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
-
setCharset
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.
-
setDefaultResponseContentCharset
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
-
addHint
-
toString
Returns a string representation of this object. -
writeObject
- Throws:
IOException
-
readObject
- Throws:
ClassNotFoundExceptionIOException
-