Class XMLHttpRequest
java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.event.EventTarget
org.htmlunit.javascript.host.xml.XMLHttpRequestEventTarget
org.htmlunit.javascript.host.xml.XMLHttpRequest
- All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
A JavaScript object for an
XMLHttpRequest.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classNested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static final String[]private static final Stringprivate booleanprivate final booleanstatic final intAll the data has been received; the complete data is available in responseBody and responseText.static final intThe send() method has been called, but the status and headers are not yet available.private booleanprivate intstatic final intSome data has been received.private static final org.apache.commons.logging.Logstatic final intThe object has been created, but the send() method has not been called.private Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate Stringprivate intprivate intstatic final intThe object has been created, but not initialized (the open() method has not been called).private WebRequestprivate WebResponseprivate booleanFields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONSTFields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.XMLHttpRequest(boolean caseSensitiveProperties) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Cancels the current HTTP request.(package private) voiddoSend()The real send job.private voidfireJavascriptEvent(String eventName) private voidfireJavascriptEventIgnoreAbort(String eventName) Gets a named property from the object.Returns the labels and values of all the HTTP headers.org.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on ready state change.intReturns the current state of the HTTP request.getResponseHeader(String headerName) 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.intReturns 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".intReturns theuploadproperty.(package private) static booleanisAuthorizedHeader(String name) Not all request headers can be set from JavaScript.private booleanprivate booleanisPreflightAuthorized(WebResponse preflightResponse) private static booleanisPreflightHeader(String name, String value) private static booleanisSameOrigin(URL originUrl, URL newUrl) booleanReturns thewithCredentialsproperty.voidJavaScript constructor.voidAssigns the destination URL, method and other optional attributes of a pending request.voidoverrideMimeType(String mimeType) Override the mime type returned by the server (if any).private voidprepareRequestContent(Object content) Prepares the WebRequest that will be sent.voidvoidSends the specified content to the server in an HTTP request and receives the response.voidsetOnreadystatechange(org.htmlunit.corejs.javascript.Function readyStateChangeHandler) Sets the event handler that fires on ready state change.voidsetRequestHeader(String name, String value) Sets the specified header to the specified value.voidsetResponseType(String responseType) Sets theresponseTypeproperty.private voidsetState(int state) Sets the state as specified and invokes the state change handler if one has been set.voidsetTimeout(int timeout) voidsetWithCredentials(boolean withCredentials) Sets thewithCredentialsproperty.Methods inherited from class XMLHttpRequestEventTarget
getOnabort, getOnerror, getOnload, getOnloadend, getOnloadstart, getOnprogress, getOntimeout, setOnabort, setOnerror, setOnload, setOnloadend, setOnloadstart, setOnprogress, setOntimeoutMethods inherited from class EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandlerMethods inherited from class HtmlUnitScriptable
clone, equivalentValues, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
UNSENT
public static final int UNSENTThe object has been created, but not initialized (the open() method has not been called).- See Also:
-
OPENED
public static final int OPENEDThe object has been created, but the send() method has not been called.- See Also:
-
HEADERS_RECEIVED
public static final int HEADERS_RECEIVEDThe send() method has been called, but the status and headers are not yet available.- See Also:
-
LOADING
public static final int LOADINGSome data has been received.- See Also:
-
DONE
public static final int DONEAll the data has been received; the complete data is available in responseBody and responseText.- See Also:
-
RESPONSE_TYPE_DEFAULT
- See Also:
-
RESPONSE_TYPE_ARRAYBUFFER
- See Also:
-
RESPONSE_TYPE_BLOB
- See Also:
-
RESPONSE_TYPE_DOCUMENT
- See Also:
-
RESPONSE_TYPE_JSON
- See Also:
-
RESPONSE_TYPE_TEXT
- See Also:
-
ALLOW_ORIGIN_ALL
- See Also:
-
ALL_PROPERTIES_
-
PROHIBITED_HEADERS_
-
state_
private int state_ -
webRequest_
-
async_
private boolean async_ -
jobID_
private int jobID_ -
webResponse_
-
overriddenMimeType_
-
caseSensitiveProperties_
private final boolean caseSensitiveProperties_ -
withCredentials_
private boolean withCredentials_ -
isSameOrigin_
private boolean isSameOrigin_ -
timeout_
private int timeout_ -
aborted_
private boolean aborted_ -
responseType_
-
-
Constructor Details
-
XMLHttpRequest
public XMLHttpRequest()Creates a new instance. -
XMLHttpRequest
public XMLHttpRequest(boolean caseSensitiveProperties) Creates a new instance.- Parameters:
caseSensitiveProperties- if properties and methods are case sensitive
-
-
Method Details
-
jsConstructor
public void jsConstructor()JavaScript constructor.- Overrides:
jsConstructorin classXMLHttpRequestEventTarget
-
setState
private void setState(int state) Sets the state as specified and invokes the state change handler if one has been set.- Parameters:
state- the new state
-
fireJavascriptEvent
-
fireJavascriptEventIgnoreAbort
-
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
- Returns:
- the
responseTypeproperty
-
setResponseType
Sets theresponseTypeproperty.- Parameters:
responseType- theresponseTypeproperty.
-
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
Returns a string version of the data retrieved from the server.- Returns:
- a string version of the data retrieved from the server
-
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
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
Returns the labels and values of all the HTTP headers.- Returns:
- the labels and values of all the HTTP headers
-
getResponseHeader
-
open
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 toasyncParam- Whether or not to send the request to the server asynchronously, defaults totrueuser- If authentication is needed for the specified URL, the username to use to authenticatepassword- If authentication is needed for the specified URL, the password to use to authenticate
-
isSameOrigin
-
send
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
-
prepareRequestContent
Prepares the WebRequest that will be sent.- Parameters:
content- the content to send
-
doSend
void doSend()The real send job. -
isPreflight
private boolean isPreflight() -
isPreflightAuthorized
-
isPreflightHeader
-
setRequestHeader
-
isAuthorizedHeader
Not all request headers can be set from JavaScript.- Parameters:
name- the header name- Returns:
trueif the header can be set from JavaScript- See Also:
-
overrideMimeType
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 thewithCredentialsproperty.- Returns:
- the
withCredentialsproperty
-
setWithCredentials
public void setWithCredentials(boolean withCredentials) Sets thewithCredentialsproperty.- Parameters:
withCredentials- thewithCredentialsproperty.
-
get
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 utilityHtmlUnitScriptable.getWithPreemption(String).- Specified by:
getin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
getin classHtmlUnitScriptable
-
put
- Specified by:
putin interfaceorg.htmlunit.corejs.javascript.Scriptable- Overrides:
putin classHtmlUnitScriptable
-
getUpload
-
getOnreadystatechange
public org.htmlunit.corejs.javascript.Function getOnreadystatechange()Returns the event handler that fires on ready state change.- Overrides:
getOnreadystatechangein classXMLHttpRequestEventTarget- 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:
setOnreadystatechangein classXMLHttpRequestEventTarget- Parameters:
readyStateChangeHandler- the event handler that fires on ready state change
-
getTimeout
public int getTimeout() -
setTimeout
public void setTimeout(int timeout)
-