Freigeben über


IXMLHTTPRequest

 

Provides client-side protocol support for communication with HTTP servers.

Example

The following Microsoft® JScript® example creates an XMLHTTP object and asks a server for an XML document. The server sends back an XML document, which is then displayed in a message box.

var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.6.0");  
xmlHttpReq.open("GET", "https://localhost/books.xml", false);  
xmlHttpReq.send();  
WScript.Echo(xmlHttpReq.responseText);  
  

Example

The following C/C++ example creates an XMLHTTP object and asks a server for an XML document. The server sends back an XML document that is displayed by the code snippet.

#import "msxml6.dll"  
using namespace MSXML2;  
  
void XMLHttpRequestSample()  
{  
   IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;  
   BSTR bstrString = NULL;  
   HRESULT hr;  
  
   try {  
      hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.6.0");  
      SUCCEEDED(hr) ? 0 : throw hr;  
  
      hr=pIXMLHTTPRequest->open("GET", "https://localhost/books.xml ", false);  
      SUCCEEDED(hr) ? 0 : throw hr;  
  
      hr=pIXMLHTTPRequest->send();  
      SUCCEEDED(hr) ? 0 : throw hr;  
  
      bstrString=pIXMLHTTPRequest->responseText;  
  
      MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);  
  
      if(bstrString)  
      {  
         ::SysFreeString(bstrString);  
         bstrString = NULL;  
      }  
  
   } catch (...) {  
      MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);  
      if(bstrString)  
         ::SysFreeString(bstrString);  
   }  
  
}  
  

Remarks

A client computer can use the XMLHTTP object (MSXML2.XMLHTTP.3.0) to send an arbitrary HTTP request, receive the response, and have the Microsoft® XML Document Object Model (DOM) parse that response.

This object is integrated with Microsoft XML Core Services (MSXML) to support sending the request body directly from, and parsing the response directly into, the MSXML DOM objects. When combined with the support for Extensible Stylesheet Language (XSL), the XMLHTTP component provides an easy way to send structured queries to HTTP servers and efficiently display the results with a variety of presentations.

The usual sequence is to call the open method, set any custom header information through the setRequestHeader method followed by the send method, and then to check one of the four different response properties.

The XMLHTTP object is supported in Microsoft Internet Explorer (IE) 5.0 or later, as long as your browser settings specify at least one language for use when Web pages are viewed. For more information, see the topic entitled "To specify another language for Web page content" in Internet Explorer Help.

Versioning

Implemented in: MSXML 3.0 and later

Requirements

Implementation:

msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

Header and IDL files: msxml2.h, msxml2.idl, msxml6.h, msxml6.idl

See Also

IXMLHTTPRequest Members
IXMLDOMDocument-DOMDocument