XML-IXMLHTTPRequest 使用
来源:互联网 发布:智能物流软件 编辑:程序博客网 时间:2024/06/07 02:59
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);
}
}