1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
#include <tchar.h>
#include <fstream>
#define WIN32_LEAN_AND_MEAN
#ifdef MSVC
#pragma comment(lib,"wininet")
#endif
int _tmain(int argc, _TCHAR* argv[])
{
HINTERNET init, cnxn, file;
DWORD dwBytes;
TCHAR ch;
/*initialize the wininet library*/
init = InternetOpen("HTTPGET",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
0);
/*connect to the server*/
cnxn = InternetConnect(init,
argv[1],
INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
/*open up an HTTP request*/
file = HttpOpenRequest(cnxn,
NULL,
"/index.html",
NULL,
NULL,
NULL,
0,
0);
std::ofstream webSrc;
if(HttpSendRequest(file, NULL, 0, NULL, 0))
{
webSrc.open(_tcscat(argv[1], _T("___.html")));
while(InternetReadFile(file, &ch, 1, &dwBytes))
{
if(dwBytes != 1) break;
webSrc << ch;
}
webSrc.close();
}
InternetCloseHandle(file);
InternetCloseHandle(cnxn);
InternetCloseHandle(init);
return 0;
}
|