c++实现发送http请求通过get方式获取网页源代码
c++实现发送http请求通过get方式获取网页源代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:#include#include#include#defineMAXSIZE1024#pragmacomment(lib,...

复制代码 代码如下:

#include <stdio.h>

#include <windows.h>

#include <wininet.h>

#define MAXSIZE 1024

#pragma comment(lib, "Wininet.lib")

void urlopen(_TCHAR*);

int _tmain(int argc, _TCHAR* argv[])

{

urlopen(_T("http://www.jb51.net"));

return 0;

}

void urlopen(_TCHAR* url)

{

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("%sn"), url);

BYTE Temp[MAXSIZE];

ULONG Number = 1;

while (Number > 0)

{

InternetReadFile(hHttp, Temp, MAXSIZE - 1, &Number);

Temp[Number] = '';

printf("%s", Temp);

}

InternetCloseHandle(hHttp);

hHttp = NULL;

}

InternetCloseHandle(hSession);

hSession = NULL;

}

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C语言学习
热门C语言学习
编程开发子分类