Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

getResponseHeader Method (IXMLHTTPRequest)

Retrieves the value of an HTTP header from the response body.

[Script]

Script Syntax

strValue = oXMLHttpRequest.getResponseHeader(bstrHeader);

Parameters

bstrHeader
A string containing the case-insensitive header name.

Return Value

A string. Contains the resulting header information.

Example

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.5.0");
xmlhttp.open("GET", "http://localhost/sample.xml", false);
xmlhttp.send();
alert(xmlhttp.getResponseHeader("Content-Length"));
[Visual Basic]

Visual Basic Syntax

strValue = oXMLHttpRequest.getResponseHeader(bstrHeader)

Parameters

bstrHeader
A string containing the case-insensitive header name.

Return Value

A string. Contains the resulting header information.

Example

Dim xmlhttp As New Msxml2.XMLHTTP50
xmlhttp.open "GET", "http://localhost/sample.xml", False
xmlhttp.send
MsgBox xmlhttp.getResponseHeader("Content-Length")
[C/C++]

C/C++ Syntax

HRESULT getResponseHeader(BSTR bstrHeader, BSTR* pbstrValue);

Parameters

bstrHeader [in]
A case-insensitive header name.
pbstrValue [out, retval]
The resulting header information.

C/C++ Return Values

S_OK
The value returned if successful.

C/C++ Example

HRESULT hr;
BSTR bstrValue = NULL;
IXMLHttpRequest *pIXMLHttpRequest = NULL;

try
{
   // Create XMLHttpRequest object and initialize pIXMLHttpRequest.
   hr = pIXMLHttpRequest->getResponseHeader(_T("Server"), &bstrValue);
   if(SUCCEEDED(hr))
   {
      ::MessageBox(NULL, m_bstrValue, _T("Response Header-Server"), MB_OK);   
      ::SysFreeString(bstrValue);
      bstrValue = NULL;
   }   
}
catch(...)
{
   if(bstrValue)
      ::SysFreeString(bstrValue);
   DisplayErrorToUser();
}
// Release pIXMLHttpRequest when finished with it.

Remarks

The results of this method are valid only after the send method has been successfully completed. The line, xmlhttp.getResponseHeader("Content-Type");, returns the string "text/xml", assuming the server set "text/xml" as the content type. The full list of header variables you can query can be accessed from the getAllResponseHeaders method.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

getAllResponseHeaders Method (IXMLHTTPRequest) | send Method (IXMLHTTPRequest) | setRequestHeader Method (IXMLHTTPRequest)

Applies to: IXMLHTTPRequest