#include <windows.h>
#include <wininet.h>
#include <fstream>
using namespace std;
#pragma comment(lib,"Wininet.lib")
int main(int argc, char* argv[])
{
TCHAR szUrl[] = _T("http://www.baidu.com");
TCHAR szAgent[] = _T("");
HINTERNET hInternet1 = InternetOpen(_T("Microsoft Internet Explorer"),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if (NULL == hInternet1)
{
InternetCloseHandle(hInternet1);
return FALSE;
}
HINTERNET hInternet2 = InternetOpenUrl(hInternet1,szUrl,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,NULL);
if (NULL == hInternet2)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return FALSE;
}
char szBuffer[1024] = {0};
DWORD dwByteRead = 0;
ofstream ofs(_T("page.html"));
// 循环读取缓冲区内容直到结束
while (InternetReadFile(hInternet2, szBuffer, 1023, &dwByteRead) && dwByteRead > 0)
{
ofs<<szBuffer;
// 清空缓冲区以备下一次读取
ZeroMemory(szBuffer, sizeof(szBuffer));
}
ofs.close();
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return 0;
}
VC++获取某个http网页内容
最新推荐文章于 2021-11-19 15:05:10 发布