Kode til at hente en internet side:
#include <windows.h>
#include <wininet.h>
#include <iostream>
int main()
{
HINTERNET Internet = InternetOpen("My Url Browser", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
if(!Internet)
{
std::cout << "Failed to open internet: " << GetLastError() << std::endl;
return 1;
}
HINTERNET Url = InternetOpenUrl(Internet, "http://www.google.com/", 0, 0, INTERNET_FLAG_RAW_DATA, 0);
if(!Url)
{
std::cout << "Failed to open Url: " << GetLastError() << std::endl;
return 2;
}
char Buffer[64*1024];
DWORD ReadLen = 0, CurrentPos = 0;
do
{
InternetReadFile(Url, (void *)(Buffer + CurrentPos), sizeof(Buffer) - CurrentPos, &ReadLen);
CurrentPos += ReadLen;
}
while(ReadLen);
Buffer[CurrentPos] = 0;
std::cout << Buffer << std::endl;
InternetCloseHandle(Url);
InternetCloseHandle(Internet);
}
Siden bliver gemt i Buffer