// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
//vs2013的win32项目,可以打印出网页的数据
//#include "stdafx.h"
#include"stdio.h"
#include <windows.h>
#include <wininet.h>#define MAXSIZE 1024
#pragma comment(lib, "Wininet.lib") //库文件
#define MAX_LOADSTRING 100//宏定义int _tmain(int argc, _TCHAR* argv[])
{ _TCHAR url[256] = { Lhttp://array.kf.gli.cn/update/1.txt" };//这可以写百度等网页都可以
HINTERNET hSession = InternetOpen(_T("UrlTest"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);//打开
if (hSession != NULL)//如果成功
{
HINTERNET hHttp = InternetOpenUrl(hSession, url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);//发送请求 if (hHttp != NULL)
{
wprintf_s(_T("%s\n"), url); BYTE Temp[MAXSIZE];
ULONG Number = 1;
while (Number > 0)
{
InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);//读取数据
Temp[Number] = '\0';
printf("%s", Temp);
}
InternetCloseHandle(hHttp);
hHttp = NULL;
}
InternetCloseHandle(hSession);
hSession = NULL;
}
getchar();
return 0;
}