我是靠谱客的博主 平淡巨人,这篇文章主要介绍[C++][原创]ubuntu上C++发送http请求get和post,现在分享给大家,希望可以做个参考。

找到一个开源项目:

GitHub - elnormous/HTTPRequest: Single-header C++ HTTP request class

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

CMakeList.txt

复制代码
1
2
3
4
5
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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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 

最后

以上就是平淡巨人最近收集整理的关于[C++][原创]ubuntu上C++发送http请求get和post的全部内容,更多相关[C++][原创]ubuntu上C++发送http请求get和post内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部