Udostępnij za pośrednictwem


getResponseHeader Method (IXMLHTTPRequest)

 

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

JScript 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.6.0");  
xmlhttp.open("GET", "https://localhost/sample.xml", false);  
xmlhttp.send();  
WScript.Echo(xmlhttp.getResponseHeader("Server"));  

Output

Returns the value of the Server field in the HTTP header, which indicates the current version of the Web server running locally. In this case, the value is "Microsoft-IIS/5.1" for Internet Information Services (IIS) version 5.1, which is the version provided if the local computer is running under Microsoft Windows XP.

C/C++ Syntax

HRESULT getResponseHeader(BSTR bstrHeader, BSTR* pbstrValue);  

Parameters

bstrHeader [in]
A case-insensitive header name.

pbstrValue [out, retval]
The resulting header information.

Return Values

S_OK
The value returned if successful.

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.

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

Applies to

IXMLHTTPRequest

See Also

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