手机
当前位置:查字典教程网 >编程开发 >C语言 >c++实现发送http请求通过get方式获取网页源代码
c++实现发送http请求通过get方式获取网页源代码
摘要:复制代码代码如下:#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++实现发送http请求通过get方式获取网页源代码】相关文章:

k均值算法c++语言实现代码

C语言实现静态链表的方法

如何使用递归和非递归方式反转单向链表

C与C++中结构体的区别

C实现分子沉积模拟的示例代码

用C++实现一个链式栈的实例代码

用c语言实现HUP信号重启进程的方法

Microsoft Visual C++ 程序的部署方法

用C实现添加和读取配置文件函数

使用C++实现全排列算法的方法详解

精品推荐
分类导航