# 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 下载量 170 浏览量
2023-08-10
11:21:34
上传
评论
收藏 31KB ZIP 举报
温馨提示
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.zip (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币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- sony 索尼IMX334摄像头模组电路板AD版硬件PCB图(6层板).zip
- 基于flask和echarts融合交易策略的bitfinex可视化微服务.zip
- 包含了wvp-assist.tar wvp-talk.tar zlmediakit.tar .
- 3r4efgh53wgrf43tw
- 2024新版Java基础从入门到精通全套视频+资料下载
- Spring AI大模型视频教程+ChatGPT视频教程+OpenAI大模型视频教程(资料+视频教程)
- ABB工业机器人教程PDF版本
- 123321123323211
- yolov8实战第八天-pyqt5-yolov8实现车牌识别系统(论文(8700+字+数据集+完整部署代码+代码使用说明)
- 三相桥式全桥整流电路MATALB Simulink仿真文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功