com.gargoylesoftware.htmlunit
Class WebRequest

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebRequest
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
WebRequestSettings

public class WebRequest
extends Object
implements Serializable

Parameter object for making web requests.

Version:
$Revision: 6343 $
Author:
Brad Clarke, Hans Donner, Ahmed Ashour, Marc Guillemot, Rodney Gitzel, Ronald Brill
See Also:
Serialized Form

Constructor Summary
WebRequest(URL url)
          Instantiates a WebRequest for the specified URL.
WebRequest(URL url, HttpMethod submitMethod)
          Instantiates a WebRequest for the specified URL using the specified HTTP submit method.
WebRequest(WebRequest originalRequest, URL url)
          Instantiates a WebRequest for the specified URL using the proxy configuration from the specified original request.
 
Method Summary
 Map<String,String> getAdditionalHeaders()
          Returns the additional HTTP headers to use.
 String getCharset()
          Returns the character set to use to perform the request.
 Credentials getCredentials()
          Returns the credentials to use.
 FormEncodingType getEncodingType()
          Returns the form encoding type to use.
 HttpMethod getHttpMethod()
          Returns the HTTP submit method to use.
 String getProxyHost()
          Returns the proxy host to use.
 int getProxyPort()
          Returns the proxy port to use.
 String getRequestBody()
          Returns the body content to be submitted if this is a POST request.
 List<NameValuePair> getRequestParameters()
          Retrieves the request parameters to use.
 URL getUrl()
          Returns the target URL.
 Credentials getUrlCredentials()
          Returns the credentials to use.
 boolean isAdditionalHeader(String name)
          Returns whether the specified header name is already included in the additional HTTP headers.
 boolean isSocksProxy()
          Returns whether SOCKS proxy or not.
 void removeAdditionalHeader(String name)
          Removed the specified name/value pair from the additional HTTP headers.
 void setAdditionalHeader(String name, String value)
          Sets the specified name/value pair in the additional HTTP headers.
 void setAdditionalHeaders(Map<String,String> additionalHeaders)
          Sets the additional HTTP headers to use.
 void setCharset(String charset)
          Sets the character set to use to perform the request.
 void setCredentials(Credentials credentials)
          Sets the credentials to use.
 void setEncodingType(FormEncodingType encodingType)
          Sets the form encoding type to use.
 void setHttpMethod(HttpMethod submitMethod)
          Sets the HTTP submit method to use.
 void setProxyHost(String proxyHost)
          Sets the proxy host to use.
 void setProxyPort(int proxyPort)
          Sets the proxy port to use.
 void setRequestBody(String requestBody)
          Sets the body content to be submitted if this is a POST or PUT request.
 void setRequestParameters(List<NameValuePair> requestParameters)
          Sets the request parameters to use.
 void setSocksProxy(boolean isSocksProxy)
          Sets whether SOCKS proxy or not.
 void setUrl(URL url)
          Sets the target URL.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebRequest

public WebRequest(URL url)
Instantiates a WebRequest for the specified URL.

Parameters:
url - the target URL

WebRequest

public WebRequest(WebRequest originalRequest,
                  URL url)
Instantiates a WebRequest for the specified URL using the proxy configuration from the specified original request.

Parameters:
originalRequest - the original request
url - the target URL

WebRequest

public WebRequest(URL url,
                  HttpMethod submitMethod)
Instantiates a WebRequest for the specified URL using the specified HTTP submit method.

Parameters:
url - the target URL
submitMethod - the HTTP submit method to use
Method Detail

getUrl

public URL getUrl()
Returns the target URL.

Returns:
the target URL

setUrl

public void setUrl(URL url)
Sets the target URL. The URL may be simplified if needed (for instance eliminating irrelevant path portions like "/./").

Parameters:
url - the target URL

getProxyHost

public String getProxyHost()
Returns the proxy host to use.

Returns:
the proxy host to use

setProxyHost

public void setProxyHost(String proxyHost)
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

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

getEncodingType

public FormEncodingType getEncodingType()
Returns the form encoding type to use.

Returns:
the form encoding type to use

setEncodingType

public void setEncodingType(FormEncodingType encodingType)
Sets the form encoding type to use.

Parameters:
encodingType - the form encoding type to use

getRequestParameters

public List<NameValuePair> getRequestParameters()
Retrieves the request parameters to use. If set, these request parameters will overwrite any request parameters which may be present in the URL. Should not be used in combination with the request body.

Returns:
the request parameters to use

setRequestParameters

public void setRequestParameters(List<NameValuePair> requestParameters)
                          throws RuntimeException
Sets the request parameters to use. If set, these request parameters will overwrite any request parameters which may be present in the URL. Should not be used in combination with the request body.

Parameters:
requestParameters - the request parameters to use
Throws:
RuntimeException - if the request body has already been set

getRequestBody

public String getRequestBody()
Returns the body content to be submitted if this is a POST request. Ignored for all other request types. Should not be used in combination with request parameters.

Returns:
the body content to be submitted if this is a POST request

setRequestBody

public void setRequestBody(String requestBody)
                    throws RuntimeException
Sets the body content to be submitted if this is a POST or PUT request. Ignored for all other request types. Should not be used in combination with request parameters.

Parameters:
requestBody - the body content to be submitted if this is a POST request
Throws:
RuntimeException - if the request parameters have already been set or this is not a POST or PUT request

getHttpMethod

public HttpMethod getHttpMethod()
Returns the HTTP submit method to use.

Returns:
the HTTP submit method to use

setHttpMethod

public void setHttpMethod(HttpMethod submitMethod)
Sets the HTTP submit method to use.

Parameters:
submitMethod - the HTTP submit method to use

getAdditionalHeaders

public Map<String,String> getAdditionalHeaders()
Returns the additional HTTP headers to use.

Returns:
the additional HTTP headers to use

setAdditionalHeaders

public void setAdditionalHeaders(Map<String,String> additionalHeaders)
Sets the additional HTTP headers to use.

Parameters:
additionalHeaders - the additional HTTP headers to use

isAdditionalHeader

public boolean isAdditionalHeader(String name)
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

setAdditionalHeader

public void setAdditionalHeader(String name,
                                String value)
Sets the specified name/value pair in the additional HTTP headers.

Parameters:
name - the name of the additional HTTP header
value - the value of the additional HTTP header

removeAdditionalHeader

public void removeAdditionalHeader(String name)
Removed the specified name/value pair from the additional HTTP headers.

Parameters:
name - the name of the additional HTTP header

getUrlCredentials

public Credentials getUrlCredentials()
Returns the credentials to use.

Returns:
the credentials if set as part of the url

getCredentials

public Credentials getCredentials()
Returns the credentials to use.

Returns:
the credentials if set from the external builder

setCredentials

public void setCredentials(Credentials credentials)
Sets the credentials to use.

Parameters:
credentials - the credentials to use

getCharset

public String getCharset()
Returns the character set to use to perform the request.

Returns:
the character set to use to perform the request

setCharset

public void setCharset(String charset)
Sets the character set to use to perform the request. The default value is TextUtil.DEFAULT_CHARSET.

Parameters:
charset - the character set to use to perform the request

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.