java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
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.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
JavaScript host object for
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, Ashutosh Panda
- 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
FieldsModifier and TypeFieldDescriptionstatic final intAll the data has been received; the complete data is available in responseBody and responseText.static final intThesend()method has been called, but the status and headers are not yet available.static final intSome data has been received.static final intThe object has been created, but thesend()method has not been called.static final intThe object has been created, but not initialized (theopen()method has not been called).Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, LEGACY_CONST, PERMANENT, READONLY, STRICTLY_READONLY, UNINITIALIZED_CONSTFields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
isSealedFields inherited from interface org.htmlunit.corejs.javascript.Scriptable
NOT_FOUND -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Cancels the current HTTP request.Returns all the HTTP response headers as a string.org.htmlunit.corejs.javascript.FunctionReturns the event handler that fires on ready state change.intReturns the current state of the HTTP request.Returns the response body as anArrayBuffer,Blob,Document, JavaScript object, orDOMString, depending on the value of theresponseTypeproperty.getResponseHeader(String headerName) Returns the value of the specified HTTP response header.Returns the response body as a string.Returns theresponseTypeproperty.Returns the serialized url of the response (the final url after all redirects, without the fragment).Returns a DOM-compatible document object version of the data retrieved from the server.intReturns the numeric HTTP status code returned by the server (e.g. 404 for "Not Found" or 200 for "OK").Returns the HTTP status message accompanying the status code (e.g.intReturns the number of milliseconds a request can take before automatically being terminated.Returns theuploadproperty.booleanReturns themozAnonproperty; a normal web page can't create an anonymous request, therefore this is alwaysfalse.booleanReturns themozSystemproperty; only privileged code can create a system request, therefore this is alwaysfalse.booleanReturns thewithCredentialsproperty.voidCreates an instance of this object.voidInitializes the request by specifying the destination URL, method, and other optional attributes.voidoverrideMimeType(String mimeType) Overrides the MIME type returned by the server.voidSends the request to the server with the specified content as the request body.voidsetAttributionReporting(Object options) Sets the attribution reporting options of the request (MDN).voidsetOnreadystatechange(org.htmlunit.corejs.javascript.Function readyStateChangeHandler) Sets the event handler that fires on ready state change.voidsetPrivateToken(Object options) Sets the private state token options of the request (MDN).voidsetRequestHeader(String name, String value) Sets the specified header to the specified value.voidsetResponseType(String responseType) Sets theresponseTypeproperty.voidsetTimeout(int timeout) Sets the number of milliseconds a request can take before automatically being terminated.voidsetWithCredentials(boolean withCredentials) Sets thewithCredentialsproperty.Methods inherited from class org.htmlunit.javascript.host.xml.XMLHttpRequestEventTarget
getOnabort, getOnerror, getOnload, getOnloadend, getOnloadstart, getOnprogress, getOntimeout, setOnabort, setOnerror, setOnload, setOnloadend, setOnloadstart, setOnprogress, setOntimeoutMethods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, dispatchEvent, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandlerMethods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, createDOMException, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getWindow, getWindow, getWindowOrWorkerGlobalScope, getWithPreemption, has, hasInstance, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setupPromise, setupRejectedPromiseMethods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, 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, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, 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, sizeMethods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMapsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.htmlunit.corejs.javascript.Scriptable
get, getIds, has, hasMethods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable
get, has
-
Field Details
-
UNSENT
public static final int UNSENTThe object has been created, but not initialized (theopen()method has not been called).- See Also:
-
OPENED
public static final int OPENEDThe object has been created, but thesend()method has not been called.- See Also:
-
HEADERS_RECEIVED
public static final int HEADERS_RECEIVEDThesend()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:
-
-
Constructor Details
-
XMLHttpRequest
public XMLHttpRequest()Creates a new instance.
-
-
Method Details
-
jsConstructor
public void jsConstructor()Creates an instance of this object.- Overrides:
jsConstructorin classXMLHttpRequestEventTarget
-
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 theresponseTypeproperty.- Returns:
- the
responseTypeproperty
-
setResponseType
Sets theresponseTypeproperty.- Parameters:
responseType- theresponseTypeproperty
-
getResponse
Returns the response body as anArrayBuffer,Blob,Document, JavaScript object, orDOMString, depending on the value of theresponseTypeproperty.- Returns:
- the response body
-
getResponseText
Returns the response body as a string.- 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, or
null
-
getStatus
public int getStatus()Returns the numeric HTTP status code returned by the server (e.g. 404 for "Not Found" or 200 for "OK").- Returns:
- the numeric HTTP status code
-
getResponseURL
Returns the serialized url of the response (the final url after all redirects, without the fragment).- Returns:
- the url of the response or an empty string if there is no response
-
getStatusText
Returns the HTTP status message accompanying the status code (e.g. "Not Found" or "OK").- Returns:
- the HTTP status message
-
abort
public void abort()Cancels the current HTTP request. -
getAllResponseHeaders
Returns all the HTTP response headers as a string.- Returns:
- all response header names and values as a string
-
getResponseHeader
Returns the value of the specified HTTP response header.- Parameters:
headerName- the case-insensitive name of the header to retrieve- Returns:
- the value of the specified HTTP header, or
nullif not found
-
open
Initializes the request by specifying the destination URL, method, and other optional attributes.- Parameters:
method- the HTTP method to use (e.g. GET, POST)urlParam- the URL to send the request toasyncParam- whether to send the request asynchronously; defaults totrueuser- the username to use for authentication, if requiredpassword- the password to use for authentication, if required
-
send
Sends the request to the server with the specified content as the request body.- Parameters:
content- the body of the message being sent with the request
-
setRequestHeader
Sets the specified header to the specified value. Theopen()method must be called before this method, or an error will occur.- Parameters:
name- the name of the header to setvalue- the value of the header to set
-
setAttributionReporting
Sets the attribution reporting options of the request (MDN).The attribution reporting itself is not supported, so this only validates the argument.
- Parameters:
options- the options (eventSourceEligibleandtriggerEligible)
-
setPrivateToken
Sets the private state token options of the request (MDN).Private state tokens are not supported, so this only validates the argument.
- Parameters:
options- the options (version,operation, ...)
-
overrideMimeType
Overrides the MIME type returned by the server. This must be called beforesend(). This may be used, for example, to force a stream to be treated and parsed astext/xml, even if the server does not report it as such.- Parameters:
mimeType- the MIME type to use instead of the one returned by the server
-
isWithCredentials
public boolean isWithCredentials()Returns thewithCredentialsproperty.- Returns:
- the
withCredentialsproperty
-
setWithCredentials
public void setWithCredentials(boolean withCredentials) Sets thewithCredentialsproperty.- Parameters:
withCredentials- thewithCredentialsproperty
-
isMozAnon
public boolean isMozAnon()Returns themozAnonproperty; a normal web page can't create an anonymous request, therefore this is alwaysfalse.- Returns:
false
-
isMozSystem
public boolean isMozSystem()Returns themozSystemproperty; only privileged code can create a system request, therefore this is alwaysfalse.- Returns:
false
-
getUpload
Returns theuploadproperty.- Returns:
- the
uploadproperty
-
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()Returns the number of milliseconds a request can take before automatically being terminated. A value of0means there is no timeout.- Returns:
- the timeout in milliseconds
-
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
-