Name
XMLHttpRequest.setRequestHeader( ): add a HTTP request header to the request
Synopsis
void setRequestHeader(Stringname, Stringvalue)
Arguments
-
name The name of the header to be set. This argument should not contain spaces, colons, linefeeds, or newlines.
-
value The value for the header. This argument should not contain linefeeds or newlines.
Description
setRequestHeader( )
specifies an HTTP request header that should be included in the
request issued by a subsequent call to send( ). This method may be called only
when readyState is 1—i.e., after
a call to open( ) but before a
call to send( ).
If a header with the specified name
has already been specified, the new value for that header is the
previously specified value, plus a comma, a space, and the
value specified in this call.
If the call to open( )
specifies authorization credentials, XMLHttpRequest automatically
sends an appropriate Authorization request header. You can
append to this header with setRequestHeader( ), however. Similarly,
if the web browser has stored cookies associated with the URL passed
to open( ), appropriate Cookie or Cookie2 headers are automatically included
with the request. You can append additional cookies to these headers
by calling setRequestHeader( ).
XMLHttpRequest may also provide a default value for the User-Agent header. If it does this, any
value you specify for that header is appended to the default
value.
Some request headers are automatically set by the XMLHttpRequest for conformance to the HTTP ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access