Adds custom HTTP headers to the request.
Syntax
XMLHttpRequest.setRequestHeader(sName, sValue)
Parameters
sName Required. String that specifies the header name.sValue Required. String that specifies the header value.
Return Value
No return value.
Remarks
Refer to RFC 2616, Section 14: Header Field Definitions for a general list of standard headers. The server is ultimately responsible for honoring the headers of the request. By far the most common request header is Content-Type, which is required by some XML Web services.setRequestHeader was introduced in Windows Internet Explorer 7.
Refer to RFC 2616, Section 14: Header Field Definitions for a general list of standard headers. The server is ultimately responsible for honoring the headers of the request. By far the most common request header is Content-Type, which is required by some XML Web services.
setRequestHeader was introduced in Windows Internet Explorer 7.
Example
The following script sets the HTTP Content-Type header to 'text/xml' before sending the request body: var oReq = new XMLHttpRequest(); oReq.open("POST", sURL, false); oReq.setRequestHeader("Content-Type", "text/xml"); oReq.send(sRequestBody);
The following script sets the HTTP Content-Type header to 'text/xml' before sending the request body:
var oReq = new XMLHttpRequest(); oReq.open("POST", sURL, false); oReq.setRequestHeader("Content-Type", "text/xml"); oReq.send(sRequestBody);
Standards Information
This method is defined in The XMLHttpRequest Object (W3C Working Draft) .
Applies To
XMLHttpRequest
See Also
getResponseHeader
Experience Silverlight enabled quickstart tutorials, video training, showcases & more.
By clicking "Click to Install" you accept the Silverlight License Agreement .Silverlight updates automatically, learn more .