Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1732
  • Last Modified:

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:

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


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/
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?


PS: Apologies for the improper C language zone -- my first question here!
1 Solution

You should do InternetReadFile


            /* size of the buffer */
            DWORD dwSize=WORD_BUFFER_LEN;

            /* reset number of bytes read to zero bytes */

            /* read data from the web address corresponding to the handle */
            InternetReadFile (hRequest, buffer, dwSize, &dwRead);

That's all. InternetReadFile API is all you need
fyrissianAuthor Commented:
Thanks, that did the trick. For some reason I was assuming ReadInternetFile required the presence of an actual file somewhere "out there".

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now