您好,欢迎来到99网。
搜索
您的当前位置:首页[C++][原创]ubuntu上C++发送http请求get和post

[C++][原创]ubuntu上C++发送http请求get和post

来源:99网

找到一个开源项目:

使用项目都有介绍,很简单,这里我在ubuntu上使用CMakeLists跑起来

CMakeList.txt

cmake_minimum_required (VERSION 3.10)
project(test)
add_definitions(-std=c++11)
add_executable(main main.cpp HTTPRequest.hpp)
target_link_libraries(main pthread)

main.cpp

#include<iostream>

#include "HTTPRequest.hpp"

using namespace std;


int main()
{
  try
{
    // you can pass http::InternetProtocol::V6 to Request to make an IPv6 request
    http::Request request{"http://www.baidu.com"};

    // send a get request
    const auto response = request.send("GET");
    std::cout << std::string{response.body.begin(), response.body.end()} << '\n'; // print the result
}
catch (const std::exception& e)
{
    std::cerr << "Request failed, error: " << e.what() << '\n';
}
   
}

这个库有个缺点:不支持https 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务