/*remember and add a reference to the wininet.lib
go to project / settings or ALT F7 , now go to the link tab
in the object / library modules box type in wininet.lib . click on OK
If you do not do this for linking you will be met with a number
of linker errors
*/
#include<windows.h>
#include<wininet.h>
#include<stdio.h>
int main()
{
HINTERNET Initialize,Connection,File;
DWORD dwBytes;
char ch;
/*initialize the wininet library*/
Initialize = InternetOpen("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
/*connect to the server*/
Connection = InternetConnect(Initialize,"www.yahoo.com",INTERNET_DEFAULT_HTTP_PORT,
NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
/*open up an HTTP request*/
File = HttpOpenRequest(Connection,NULL,"/index.html",NULL,NULL,NULL,0,0);
if(HttpSendRequest(File,NULL,0,NULL,0))
{
while(InternetReadFile(File,&ch,1,&dwBytes))
{
if(dwBytes != 1)break;
putchar(ch);
}
}
/*close file , terminate server connection and
deinitialize the wininet library*/
InternetCloseHandle(File);
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);
return 0;
}