c++发送http请求 c++实现发送http请求通过get方式获取网页源代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c++发送http请求 c++实现发送http请求通过get方式获取网页源代码

  2021-03-19 我要评论
想了解c++实现发送http请求通过get方式获取网页源代码的相关内容吗,在本文为您仔细讲解c++发送http请求的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c++,http请求,获取网页源代码,下面大家一起来学习吧。

复制代码 代码如下:

#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("//www.qb5200.com"));
    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("%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;
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们