// 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;
}
c++的HTTP请求返回网页数据
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C/C++ LibCurl 库实现HTTP请求
1.下载libcurl https://curl.haxx.se/download.html 2.使用vs命令行控制台,切换到 cd curl-7.70.0\winbuild 3.执行编译选项,两种方式均可
C/C++ 基础知识 #include ipad #pragma -
纯C++实现的HTTP请求(POST/GET)
纯C++实现的HTTP请求(POST/GET),支持windows和linux, 进行简单的封装, 方便调用。实现如下: 调用方法: 地址:http://www..com/lidabo/p/04533.html
#ifdef #endif firefox linux #pragma