com.gargoylesoftware.htmlunit.activex.javascript.msxml
Class XMLHTTPRequest

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLScriptable
              extended by com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLHTTPRequest
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class XMLHTTPRequest
extends MSXMLScriptable

A JavaScript object for MSXML's (ActiveX) XMLHTTPRequest.
Provides client-side protocol support for communication with HTTP servers.

Version:
$Revision: 9081 $
Author:
Daniel Gredler, Marc Guillemot, Ahmed Ashour, Stuart Begg, Ronald Brill, Sebastian Cato, Frank Danek
See Also:
MSDN documentation, Serialized Form

Field Summary
static int STATE_DONE
          All the data has been received; the complete data is available in responseBody and responseText.
static int STATE_HEADERS_RECEIVED
          The send() method has been called, but the status and headers are not yet available.
static int STATE_LOADING
          Some data has been received.
static int STATE_OPENED
          The object has been created, but the send() method has not been called.
static int STATE_UNSENT
          The object has been created, but not initialized (the open() method has not been called).
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
XMLHTTPRequest()
          Creates an instance.
 
Method Summary
 void abort()
          Cancels the current HTTP request.
 Object get(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Gets a named property from the object.
 String getAllResponseHeaders()
          Returns the values of all the HTTP headers.
 Object getOnreadystatechange()
          Returns the event handler to be called when the readyState property changes.
 int getReadyState()
          Returns the state of the request.
 String getResponseHeader(String header)
          Retrieves the value of an HTTP header from the response body.
 String getResponseText()
          Returns the response entity body as a string.
 Object getResponseXML()
          Returns the parsed response entity body.
 int getStatus()
          Returns the HTTP status code returned by a request.
 String getStatusText()
          Returns the HTTP response line status.
 void jsConstructor()
          JavaScript constructor.
 void open(String method, Object url, boolean async, Object user, Object password)
          Initializes the request and specifies the method, URL, and authentication information for the request.
 void put(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start, Object value)
          
 void send(Object body)
          Sends an HTTP request to the server and receives a response.
 void setOnreadystatechange(net.sourceforge.htmlunit.corejs.javascript.Function stateChangeHandler)
          Sets the event handler to be called when the readyState property changes.
 void setRequestHeader(String name, String value)
          Sets the specified header to the specified value.
The open method must be called before this method, or an error will occur.
 
Methods inherited from class com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLScriptable
getClassName, getEnvironment, getPrototype, makeScriptableFor, setEnvironment, setParentScope
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, getBrowserVersion, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNSENT

public static final int STATE_UNSENT
The object has been created, but not initialized (the open() method has not been called).

See Also:
Constant Field Values

STATE_OPENED

public static final int STATE_OPENED
The object has been created, but the send() method has not been called.

See Also:
Constant Field Values

STATE_HEADERS_RECEIVED

public static final int STATE_HEADERS_RECEIVED
The send() method has been called, but the status and headers are not yet available.

See Also:
Constant Field Values

STATE_LOADING

public static final int STATE_LOADING
Some data has been received.

See Also:
Constant Field Values

STATE_DONE

public static final int STATE_DONE
All the data has been received; the complete data is available in responseBody and responseText.

See Also:
Constant Field Values
Constructor Detail

XMLHTTPRequest

public XMLHTTPRequest()
Creates an instance. JavaScript objects must have a default constructor.

Method Detail

jsConstructor

public void jsConstructor()
JavaScript constructor.


getOnreadystatechange

public Object getOnreadystatechange()
Returns the event handler to be called when the readyState property changes.

Returns:
the event handler to be called when the readyState property changes

setOnreadystatechange

public void setOnreadystatechange(net.sourceforge.htmlunit.corejs.javascript.Function stateChangeHandler)
Sets the event handler to be called when the readyState property changes.

Parameters:
stateChangeHandler - the event handler to be called when the readyState property changes

getReadyState

public int getReadyState()
Returns the state of the request. The possible values are:

Returns:
the state of the request

getResponseText

public String getResponseText()
Returns the response entity body as a string.

Returns:
the response entity body as a string

getResponseXML

public Object getResponseXML()
Returns the parsed response entity body.

Returns:
the parsed response entity body

getStatus

public int getStatus()
Returns the HTTP status code returned by a request.

Returns:
the HTTP status code returned by a request

getStatusText

public String getStatusText()
Returns the HTTP response line status.

Returns:
the HTTP response line status

abort

public void abort()
Cancels the current HTTP request.


getAllResponseHeaders

public String getAllResponseHeaders()
Returns the values of all the HTTP headers.

Returns:
the resulting header information

getResponseHeader

public String getResponseHeader(String header)
Retrieves the value of an HTTP header from the response body.

Parameters:
header - the case-insensitive header name
Returns:
the resulting header information

open

public void open(String method,
                 Object url,
                 boolean async,
                 Object user,
                 Object password)
Initializes the request and specifies the method, URL, and authentication information for the request.

Parameters:
method - the HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND; for XMLHTTP, this parameter is not case-sensitive; the verbs TRACE and TRACK are not allowed.
url - the requested URL; this can be either an absolute URL or a relative URL
async - indicator of whether the call is asynchronous; the default is true (the call returns immediately); if set to true, attach an onreadystatechange property callback so that you can tell when the send call has completed
user - the name of the user for authentication
password - the password for authentication

send

public void send(Object body)
Sends an HTTP request to the server and receives a response.

Parameters:
body - the body of the message being sent with the request.

setRequestHeader

public void setRequestHeader(String name,
                             String value)
Sets the specified header to the specified value.
The open method must be called before this method, or an error will occur.

Parameters:
name - the header name to set
value - the value of the header

get

public Object get(String name,
                  net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Gets a named property from the object. Normally HtmlUnit objects don't need to overwrite this method as properties are defined on the prototypes from the XML configuration. In some cases where "content" of object has priority compared to the properties consider using utility SimpleScriptable.getWithPreemption(String). For fallback case just implement ScriptableWithFallbackGetter.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class SimpleScriptable

put

public void put(String name,
                net.sourceforge.htmlunit.corejs.javascript.Scriptable start,
                Object value)

Specified by:
put in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
put in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject


Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.