XML-IXMLHTTPRequest 使用

Example:
1.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.3.0");
xmlHttpReq.open("GET", "http://localhost/books.xml", false);
xmlHttpReq.send();
WScript.Echo(xmlHttpReq.responseText);
2.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 "msxml3.dll"
using namespace MSXML2;
void XMLHttpRequestSample()
{
   IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
   BSTR bstrString = NULL;
   HRESULT hr;
   try {
      hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.3.0");
      SUCCEEDED(hr) ? 0 : throw hr;
      hr=pIXMLHTTPRequest->open("GET", "http://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);
   }
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值