views:

72

answers:

1

I am trying to simply access a page using the WinInet APIs. Once I access it, I'd like to be able to read the contents into a string. I've already initialized the root node. Here's what I got so far:

HINTERNET hChildURL = InternetOpenUrl(hInternetRoot,
                                      LPCTSTR(CString("http://www.google.com/")),
                                      NULL,
                                      0,
                                      0,
                                      0);

After this, I know you have to utilize InternetReadFile to actually pull out the data. Can somebody provide a detailed example of how to do that. I'm not particularly familiar with C-style file functions and using buffers so please take it easy on me.

On another note, is there a different or more modern Windows API I should be using instead of ? In the long run, I've been assigned to develop an App that will act as a client and send/rec data using HTTP and HTTPS with a remote server. Am I going on the right path here?

Edit: To be more specific about requirements: It must be written in c++, it must be compatible with Win XP and onward, and it must utilize standard windows libraries only. Other than that I'm free to do as I please.

+1  A: 

Well, you just read it in one chunk at a time:

HINTERNET Request = InternetOpenUrl(...);
if(Request != NULL)
{
    BYTE Buffer[8192];
    DWORD BytesRead;
    while(InternetReadFile(Request, Buffer, 8192, &BytesRead) && BytesRead != 0)
    {
        // do something with Buffer
    }
    InternetCloseHandle(Request);
    Request = NULL;
}
Luke
w00t thanks, I'm not used to all this low level file reading bizz. I've been spoiled with Python and Java.
themaestro