Module org.htmlunit

Class XMLHttpRequest

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
org.htmlunit.corejs.javascript.ScriptableObject
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class XMLHttpRequest extends XMLHttpRequestEventTarget
A JavaScript object for an XMLHttpRequest.
Author:
Daniel Gredler, Marc Guillemot, Ahmed Ashour, Stuart Begg, Ronald Brill, Sebastian Cato, Frank Danek, Jake Cobb, Thorsten Wendelmuth, Lai Quang Duong, Sven Strickroth
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    All the data has been received; the complete data is available in responseBody and responseText.
    static final int
    The send() method has been called, but the status and headers are not yet available.
    static final int
    Some data has been received.
    static final int
    The object has been created, but the send() method has not been called.
    static final int
    The object has been created, but not initialized (the open() method has not been called).

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    isSealed

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancels the current HTTP request.
    Returns the labels and values of all the HTTP headers.
    org.htmlunit.corejs.javascript.Function
    Returns the event handler that fires on ready state change.
    int
    Returns the current state of the HTTP request.
     
    Retrieves the value of an HTTP header from the response body.
    Returns a string version of the data retrieved from the server.
     
    Returns a DOM-compatible document object version of the data retrieved from the server.
    int
    Returns the numeric status returned by the server, such as 404 for "Not Found" or 200 for "OK".
    Returns the string message accompanying the status code, such as "Not Found" or "OK".
    int
     
    Returns the upload property.
    boolean
    Returns the withCredentials property.
    void
    JavaScript constructor.
    void
    open(String method, Object urlParam, Object asyncParam, Object user, Object password)
    Assigns the destination URL, method and other optional attributes of a pending request.
    void
    Override the mime type returned by the server (if any).
    void
    send(Object content)
    Sends the specified content to the server in an HTTP request and receives the response.
    void
    setOnreadystatechange(org.htmlunit.corejs.javascript.Function readyStateChangeHandler)
    Sets the event handler that fires on ready state change.
    void
    Sets the specified header to the specified value.
    void
    setResponseType(String responseType)
    Sets the responseType property.
    void
    setTimeout(int timeout)
    Sets the number of milliseconds a request can take before automatically being terminated.
    void
    setWithCredentials(boolean withCredentials)
    Sets the withCredentials property.

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMaps

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.htmlunit.corejs.javascript.Scriptable

    get, getIds, has, has

    Methods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable

    get, has
  • Field Details

    • UNSENT

      public static final int UNSENT
      The object has been created, but not initialized (the open() method has not been called).
      See Also:
    • OPENED

      public static final int OPENED
      The object has been created, but the send() method has not been called.
      See Also:
    • HEADERS_RECEIVED

      public static final int HEADERS_RECEIVED
      The send() method has been called, but the status and headers are not yet available.
      See Also:
    • LOADING

      public static final int LOADING
      Some data has been received.
      See Also:
    • DONE

      public static final int DONE
      All the data has been received; the complete data is available in responseBody and responseText.
      See Also:
  • Constructor Details

    • XMLHttpRequest

      public XMLHttpRequest()
      Creates a new instance.
  • Method Details

    • jsConstructor

      public void jsConstructor()
      JavaScript constructor.
      Overrides:
      jsConstructor in class XMLHttpRequestEventTarget
    • getReadyState

      public int getReadyState()
      Returns the current state of the HTTP request. The possible values are:
      • 0 = unsent
      • 1 = opened
      • 2 = headers_received
      • 3 = loading
      • 4 = done
      Returns:
      the current state of the HTTP request
    • getResponseType

      public String getResponseType()
      Returns:
      the responseType property
    • setResponseType

      public void setResponseType(String responseType)
      Sets the responseType property.
      Parameters:
      responseType - the responseType property.
    • getResponse

      public Object getResponse()
      Returns:
      returns the response's body content as an ArrayBuffer, Blob, Document, JavaScript Object, or DOMString, depending on the value of the request's responseType property.
    • getResponseText

      public String getResponseText()
      Returns a string version of the data retrieved from the server.
      Returns:
      a string version of the data retrieved from the server
    • getResponseXML

      public Object getResponseXML()
      Returns a DOM-compatible document object version of the data retrieved from the server.
      Returns:
      a DOM-compatible document object version of the data retrieved from the server
    • getStatus

      public int getStatus()
      Returns the numeric status returned by the server, such as 404 for "Not Found" or 200 for "OK".
      Returns:
      the numeric status returned by the server
    • getStatusText

      public String getStatusText()
      Returns the string message accompanying the status code, such as "Not Found" or "OK".
      Returns:
      the string message accompanying the status code
    • abort

      public void abort()
      Cancels the current HTTP request.
    • getAllResponseHeaders

      public String getAllResponseHeaders()
      Returns the labels and values of all the HTTP headers.
      Returns:
      the labels and values of all the HTTP headers
    • getResponseHeader

      public String getResponseHeader(String headerName)
      Retrieves the value of an HTTP header from the response body.
      Parameters:
      headerName - the (case-insensitive) name of the header to retrieve
      Returns:
      the value of the specified HTTP header
    • open

      public void open(String method, Object urlParam, Object asyncParam, Object user, Object password)
      Assigns the destination URL, method and other optional attributes of a pending request.
      Parameters:
      method - the method to use to send the request to the server (GET, POST, etc)
      urlParam - the URL to send the request to
      asyncParam - Whether or not to send the request to the server asynchronously, defaults to true
      user - If authentication is needed for the specified URL, the username to use to authenticate
      password - If authentication is needed for the specified URL, the password to use to authenticate
    • send

      public void send(Object content)
      Sends the specified content to the server in an HTTP request and receives the response.
      Parameters:
      content - 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 name of the header being set
      value - the value of the header being set
    • overrideMimeType

      public void overrideMimeType(String mimeType)
      Override the mime type returned by the server (if any). This may be used, for example, to force a stream to be treated and parsed as text/xml, even if the server does not report it as such. This must be done before the send method is invoked.
      Parameters:
      mimeType - the type used to override that returned by the server (if any)
      See Also:
    • isWithCredentials

      public boolean isWithCredentials()
      Returns the withCredentials property.
      Returns:
      the withCredentials property
    • setWithCredentials

      public void setWithCredentials(boolean withCredentials)
      Sets the withCredentials property.
      Parameters:
      withCredentials - the withCredentials property.
    • getUpload

      public XMLHttpRequestUpload getUpload()
      Returns the upload property.
      Returns:
      the upload property
    • getOnreadystatechange

      public org.htmlunit.corejs.javascript.Function getOnreadystatechange()
      Returns the event handler that fires on ready state change.
      Overrides:
      getOnreadystatechange in class XMLHttpRequestEventTarget
      Returns:
      the event handler that fires on ready state change
    • setOnreadystatechange

      public void setOnreadystatechange(org.htmlunit.corejs.javascript.Function readyStateChangeHandler)
      Sets the event handler that fires on ready state change.
      Overrides:
      setOnreadystatechange in class XMLHttpRequestEventTarget
      Parameters:
      readyStateChangeHandler - the event handler that fires on ready state change
    • getTimeout

      public int getTimeout()
      Returns:
      the number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout.
    • setTimeout

      public void setTimeout(int timeout)
      Sets the number of milliseconds a request can take before automatically being terminated.
      Parameters:
      timeout - the timeout in milliseconds