在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:elnormous/HTTPRequest开源软件地址:https://github.com/elnormous/HTTPRequest开源编程语言:C++ 96.5%开源软件介绍:HTTPRequestHTTPRequest 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. UsageTo use the library simply include Example of a GET requesttry
{
// 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 datatry
{
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 bodytry
{
http::Request request{"http://test.com/test"};
const std::string body = "{\"foo\": 1, \"bar\": \"baz\"}";
const auto response = request.send("POST", parameters, {
{"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 authorizationtry
{
http::Request request{"http://user:[email protected]/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 LicenseHTTPRequest is released to the Public Domain. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论