Microsoft XML 2.5 SDK


 

IXMLHttpRequest::getResponseHeader Method

[This is preliminary documentation and subject to change.]

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

Visual Basic Syntax

strValue = oXMLHttpRequest.getResponseHeader(bstrHeader)

C/C++ Syntax

HRESULT getResponseHeader(

    BSTR bstrHeader,

    BSTR *pbstrValue);

Parameters

bstrHeader

[in]
Case-insensitive header name.

pbstrValue

[out]
Resulting header information.

C/C++ Return Value

Returns S_OK if successful, or an error code otherwise.

Remarks

The results of this method are valid only after the send method has been successfully completed. The following 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 that you can query can be discovered via the getAllResponseHeaders method.

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 done with it.

See Also

getAllResponseHeaders, setRequestHeader