Link to home
Start Free TrialLog in
Avatar of fyrissian
fyrissian

asked on

Getting response data from HttpQueryInfo

I've implemented a simple ASP.NET web service, which I want to access from C++ using the WinInet functions -- I want to be able to pass in a string, and retrieve a url string in reply, embedded in an XML envelope. Here are the suggested HTTP  post and reponse header info as shown by the service when run from VS2008:

HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

POST /MySimpleService.asmx/GetSomeString HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

SN=string


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.someplace.com/somepage">string</string>


The service works in the debug browser from Visual Studio. From C++ I am able to access the GetSomeString function of the service. I can step through the service in the Visual Studio debugger, and have verified that it's getting the string data and processing it correctly. When the service returns, I can get the main headers using HttpQueryInfo with the HTTP_QUERY_RAW_HEADERS_CRLF flag. However, I'm not getting the xml data. Do I need to query for that info using a separate flag?

// relevant code:
// hopen = InternetOpen(...);
// hconnect = InternetConnect(hopen, ...);
// hrequest = InternetOpenRequest(hconnect, ...);
char* hdrbuff1 = new char(4096);
unsigned long bfsize1 = 4096;
unsigned long hdrindex = 0L;
BOOL sentinfo = HttpQueryInfo(hrequest, HTTP_QUERY_RAW_HEADERS_CRLF, hdrbuff1, &bfsize1, &hdrindex);
// if not sentinfo, show error message and exit (omitted for brevity)
MessageBox(0, (const char*)hdrbuff1, NULL, 0);
 
This are the headers that I'm getting back from HttpQueryInfo above:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Tue, 05 Jan 2010 01:21:25 GMT
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 170
Connection: Close

What I am NOT getting the xml data I expected. I feel like I'm missing something obvious here, but I'm just not seeing it. Can anyone help out?

Thanks,
Kevan

PS: Apologies for the improper C language zone -- my first question here!
ASKER CERTIFIED SOLUTION
Avatar of CSecurity
CSecurity
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fyrissian
fyrissian

ASKER

Thanks, that did the trick. For some reason I was assuming ReadInternetFile required the presence of an actual file somewhere "out there".