c++利用curl 请求https

前提条件系统安装有curl

#include <iostream> // 包含输入输出流库
#include <string> // 包含输入输出流库
using std::string;

#include <cstdio> // 引入库以使用popen和pclose函数

int main() { // 主函数,程序的入口
	std::cout << "Hello, World!" << std::endl; // 输出 Hello, World!
   	readBaidu();
    string s;
    while("1"!=s){
        std::cin >> s;
        std::cout << s << std::endl;
    }
	return 0; // 表示程序正常终止
}

int readBaidu(){
    FILE* pipe = popen("curl  -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'  -H 'Referer: https://google.com?q=example' -i -k https://www.baidu.com/", "r"); // 打开管道,执行命令并读取输出
    if (!pipe) {
        return 1; // 如果打开管道失败,则退出
    }
    
    char buffer[128]; // 读取输出时使用的缓冲区
    while (!feof(pipe)) {
        if (fgets(buffer, 128, pipe) != NULL) {
            printf("%s", buffer); // 打印命令的输出
        }
    }
    
    pclose(pipe); // 关闭管道
    return 0;
}
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值