com.gargoylesoftware.htmlunit
Class WebResponse

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebResponse
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
StringWebResponse, WebResponseImpl, WebResponseWrapper

public class WebResponse
extends Object
implements Serializable

A response from a web server.

Version:
$Revision: 5834 $
Author:
Mike Bowler, Brad Clarke, Noboru Sinohara, Marc Guillemot, Ahmed Ashour
See Also:
Serialized Form

Constructor Summary
WebResponse(WebResponseData responseData, URL url, HttpMethod requestMethod, long loadTime)
          Constructs with all data.
WebResponse(WebResponseData responseData, WebRequest request, long loadTime)
          Constructs with all data.
 
Method Summary
 byte[] getContentAsBytes()
          Deprecated. as of 2.8, use either getContentAsString() or getContentAsStream().
 InputStream getContentAsStream()
          Returns the response content as an input stream.
 String getContentAsString()
          Returns the response content as a string, using the charset/encoding specified in the server response.
 String getContentAsString(String encoding)
          Returns the response content as a string, using the specified charset/encoding, rather than the charset/encoding specified in the server response.
 String getContentCharset()
          Returns the content charset for this response, even if no charset was specified explicitly.
 String getContentCharsetOrNull()
          Returns the content charset specified explicitly in the header or in the content, or null if none was specified.
 String getContentType()
          Returns the content type returned from the server, e.g.
 long getLoadTime()
          Returns the time it took to load this web response, in milliseconds.
 WebRequest getRequestSettings()
          Deprecated. as of 2.8, please use getWebRequest() instead
 URL getRequestUrl()
          Deprecated. as of 2.6, please use getWebRequest().getUrl()
 List<NameValuePair> getResponseHeaders()
          Returns the response headers as a list of NameValuePairs.
 String getResponseHeaderValue(String headerName)
          Returns the value of the specified response header.
 int getStatusCode()
          Returns the status code that was returned by the server.
 String getStatusMessage()
          Returns the status message that was returned from the server.
 WebRequest getWebRequest()
          Returns the request used to load this response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebResponse

public WebResponse(WebResponseData responseData,
                   URL url,
                   HttpMethod requestMethod,
                   long loadTime)
Constructs with all data.

Parameters:
responseData - Data that was send back
url - Where this response came from
requestMethod - the method used to get this response
loadTime - How long the response took to be sent

WebResponse

public WebResponse(WebResponseData responseData,
                   WebRequest request,
                   long loadTime)
Constructs with all data.

Parameters:
responseData - Data that was send back
request - the request used to get this response
loadTime - How long the response took to be sent
Method Detail

getRequestSettings

@Deprecated
public WebRequest getRequestSettings()
Deprecated. as of 2.8, please use getWebRequest() instead

Returns the request used to load this response.

Returns:
the request used to load this response

getWebRequest

public WebRequest getWebRequest()
Returns the request used to load this response.

Returns:
the request used to load this response

getResponseHeaders

public List<NameValuePair> getResponseHeaders()
Returns the response headers as a list of NameValuePairs.

Returns:
the response headers as a list of NameValuePairs

getResponseHeaderValue

public String getResponseHeaderValue(String headerName)
Returns the value of the specified response header.

Parameters:
headerName - the name of the header whose value is to be returned
Returns:
the header value, null if no response header exists with this name

getStatusCode

public int getStatusCode()
Returns the status code that was returned by the server.

Returns:
the status code that was returned by the server

getStatusMessage

public String getStatusMessage()
Returns the status message that was returned from the server.

Returns:
the status message that was returned from the server

getContentType

public String getContentType()
Returns the content type returned from the server, e.g. "text/html".

Returns:
the content type returned from the server, e.g. "text/html"

getContentCharsetOrNull

public String getContentCharsetOrNull()
Returns the content charset specified explicitly in the header or in the content, or null if none was specified.

Returns:
the content charset specified explicitly in the header or in the content, or null if none was specified

getContentCharset

public String getContentCharset()
Returns the content charset for this response, even if no charset was specified explicitly. This method always returns a valid charset. This method first checks the "Content-Type" header; if not found, it checks the response content; as a last resort, this method returns TextUtil.DEFAULT_CHARSET.

Returns:
the content charset for this response

getContentAsString

public String getContentAsString()
Returns the response content as a string, using the charset/encoding specified in the server response.

Returns:
the response content as a string, using the charset/encoding specified in the server response

getContentAsString

public String getContentAsString(String encoding)
Returns the response content as a string, using the specified charset/encoding, rather than the charset/encoding specified in the server response. If the specified charset/encoding is not supported then the default system encoding is used.

Parameters:
encoding - the charset/encoding to use to convert the response content into a string
Returns:
the response content as a string

getContentAsStream

public InputStream getContentAsStream()
Returns the response content as an input stream.

Returns:
the response content as an input stream

getContentAsBytes

@Deprecated
public byte[] getContentAsBytes()
Deprecated. as of 2.8, use either getContentAsString() or getContentAsStream().

Returns the response content as a byte array.

Returns:
the response content as a byte array

getLoadTime

public long getLoadTime()
Returns the time it took to load this web response, in milliseconds.

Returns:
the time it took to load this web response, in milliseconds

getRequestUrl

@Deprecated
public URL getRequestUrl()
Deprecated. as of 2.6, please use getWebRequest().getUrl()

Returns the URL that was used to load this page.

Returns:
the URL that was used to load this page


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