This C/C++ code performs the following steps:
IXMLHTTPRequest
object, pIXMLHTTPRequest
.open
method and the send
method to request the contact information for "John Doe".responseXML
property to retrieve the XML data returned from the server.C/C++ Source File (XMLOverHTTP.cpp)
#include <stdio.h> #import <msxml5.dll> using namespace MSXML2; int main(int argc, char* argv[]) { CoInitialize(NULL); IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL; IXMLDOMDocumentPtr pXMLDoc = NULL; BSTR bstrString = NULL; HRESULT hr; try { hr=pIXMLHTTPRequest.CreateInstance(__uuidof(XMLHTTP50)); SUCCEEDED(hr) ? 0 : throw hr; hr=pIXMLHTTPRequest->open("GET", "http://localhost/sxh/contact.asp?SearchID=John Doe", false); SUCCEEDED(hr) ? 0 : throw hr; hr=pIXMLHTTPRequest->send(); SUCCEEDED(hr) ? 0 : throw hr; pXMLDoc=pIXMLHTTPRequest->responseXML; bstrString=pXMLDoc->xml; if(bstrString) { printf("%S\n", bstrString); SysFreeString(bstrString); bstrString = NULL; } } catch (...) { printf("error: %x\n",hr); } if(bstrString) SysFreeString(bstrString); if (pIXMLHTTPRequest) pIXMLHTTPRequest.Release(); if (pXMLDoc) pXMLDoc.Release(); CoUninitialize(); return 0; }
To add the XMLOverHTTP source code to the project
Next, we'll set up a virtual directory. You must complete this step before you build and run the application.