# HTTPRequest
HTTPRequest is a single-header C++ library for making HTTP requests. You can just include it in your project and use it. HTTPRequest was tested on macOS, Windows, Haiku, BSD, and GNU/Linux, but it should work on most of the Linux-based platforms. Supports IPv4 and IPv6. HTTRequest requires C++17 or newer.
## Usage
To use the library simply include `HTTPRequest.hpp` using `#include "HTTPRequest.hpp"`.
### Example of a GET request
```cpp
try
{
// you can pass http::InternetProtocol::V6 to Request to make an IPv6 request
http::Request request{"http://test.com/test"};
// 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';
}
```
### Example of a POST request with form data
```cpp
try
{
http::Request request{"http://test.com/test"};
const string body = "foo=1&bar=baz";
const auto response = request.send("POST", body, {
{"Content-Type", "application/x-www-form-urlencoded"}
});
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';
}
```
### Example of a POST request with a JSON body
```cpp
try
{
http::Request request{"http://test.com/test"};
const std::string body = "{\"foo\": 1, \"bar\": \"baz\"}";
const auto response = request.send("POST", body, {
{"Content-Type", "application/json"}
});
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';
}
```
### Example of a GET request using Basic authorization
```cpp
try
{
http::Request request{"http://user:password@test.com/test"};
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';
}
```
To set a timeout for HTTP requests, pass `std::chrono::duration` as a last parameter to `send()`. A negative duration (default) passed to `send()` disables timeout.
## License
HTTPRequest is released to the Public Domain.
没有合适的资源?快使用搜索试试~ 我知道了~
HTTPRequest 源码
共24个文件
cpp:4个
yml:2个
xcworkspacedata:2个
需积分: 0 0 下载量 9 浏览量
2023-08-10
11:22:36
上传
评论
收藏 25KB 7Z 举报
温馨提示
HTTPRequest is a single-header C++ library for making HTTP requests. You can just include it in your project and use it. HTTPRequest was tested on macOS, Windows, Haiku, BSD, and GNU/Linux, but it should work on most of the Linux-based platforms. Supports IPv4 and IPv6. HTTRequest requires C++17 or newer. HTTPRequest is a single-header C++ library for making HTTP requests. You can just include it in your project and use it. HTTPRequest was tested on macOS, Windows, Haiku, BSD, and GNU/Linux, but
资源推荐
资源详情
资源评论
收起资源包目录
HTTPRequest-master.7z (24个子文件)
HTTPRequest-master
UNLICENSE 1KB
include
HTTPRequest.hpp 53KB
CMakeLists.txt 494B
.circleci
config.yml 925B
sonar-project.properties 489B
tests
tests.vcxproj 8KB
CMakeLists.txt 422B
Makefile 678B
tests.xcodeproj
project.pbxproj 11KB
project.xcworkspace
contents.xcworkspacedata 150B
main.cpp 54B
tests.sln 1KB
parsing.cpp 15KB
encoding.cpp 2KB
azure-pipelines.yml 1KB
.gitmodules 100B
.gitignore 714B
external
Catch2
example
example.sln 1KB
Makefile 800B
main.cpp 3KB
example.vcxproj 8KB
example.xcodeproj
project.pbxproj 9KB
project.xcworkspace
contents.xcworkspacedata 152B
README.md 2KB
共 24 条
- 1
资源评论
Knowledgebase
- 粉丝: 180
- 资源: 50
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现夜间车牌识别程序(1).rar
- 基于matlab实现无线传感器网络无需测距定位算法matlab源代码 包括apit,dv-hop,amorphous在内的共7个
- 基于python的yolov5实现的旋转目标检测
- 基于matlab实现无线传感器网络 CAB定位仿真程序 这是无线传感器节点定位CAB算法的仿真程序,由matlab完成.rar
- 基于matlab实现图像处理,本程序使用背景差分法对来往车辆进行检测和跟踪.rar
- 基于matlab实现视频监控中车型识别代码,自己写的,希望和大家多多交流.rar
- springcodespringcodespringcodespringcode
- 基于matlab实现权值的MAXDEV无线传感器网络定位算法研究 MAXDEV 无线传感器 定位 算法.rar
- sdk.config
- 基于matlab实现配电网三相潮流计算方法,对几种常用的配电网潮流计算方法进行了对比分析.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功