Getting response data from HttpQueryInfo

Posted on 2010-01-04
Last Modified: 2012-05-08
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="">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!
Question by:fyrissian
    LVL 17

    Accepted Solution


    You should do InternetReadFile

    BYTE buffer[WORD_BUFFER_LEN + 1];

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

    Author Closing Comment

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now