Use WinInet to Download a Web Page

Use WinInet to Download a Web Page

Include <WinInet.h> && link wininet.lib


//
 
#include <windows.h>
#include <WinInet.h>
#include <string>
 
int main(int argc, char* argv[])
{
    HINTERNET hINet, hFile;
    std::string strWeb;
 
    hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
    hFile = InternetOpenUrl( hINet, "http://web.ezpeer.com/api/get_singer.php?i=1&j=all", NULL, 0, 0, 0 );
    if ( hFile )
    {
        CHAR buffer[1024];
        DWORD dwRead;
        while ( InternetReadFile( hFile, buffer, 1023, &dwRead ) )
        {
            if ( dwRead == 0 )
                break;
            buffer[dwRead] = 0;
            strWeb += buffer;
        }
        InternetCloseHandle( hFile );
    }
    InternetCloseHandle( hINet );
 
    printf("%s", strWeb.c_str());
 
    return 0;
}

 

Dotblogs 的標籤: , , ,