手机
当前位置:查字典教程网 >编程开发 >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方式获取网页源代码】相关文章:

用C# 实现鼠标框选效果的实现代码

C++中事件机制的简洁实现及需要放弃的特性

新旧MFC版本实现CEdit透明的2种方法的实例代码

c语言冒泡排序法代码

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

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

用c++实现x的y次幂的代码

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

用C++实现队列的程序代码

C++实现基数排序的方法详解

精品推荐
分类导航