Debian Codegraph @

docpages/example_code/http_request.cpp

raw
1 #include <dpp/dpp.h>
2 #include <iostream>
3
4 int main() {
5 dpp::cluster bot("token");
6
7 bot.on_log(dpp::utility::cout_logger());
8
9 bot.on_ready([&bot](const dpp::ready_t& event) {
10 // Arbitrary post data as a string
11 std::string mypostdata = "{\"value\": 42}";
12 // Make a HTTP POST request. HTTP and HTTPS are supported here.
13 bot.request(
14 "http://www.somebotlist.com/api/servers", dpp::m_post, [](const dpp::http_request_completion_t& cc) {
15 // This callback is called when the HTTP request completes. See documentation of
16 // dpp::http_request_completion_t for information on the fields in the parameter.
17 std::cout << "I got reply: " << cc.body << " with HTTP status code: " << cc.status << "\n";
18 },
19 mypostdata,
20 "application/json",
21 {
22 {"Authorization", "Bearer tokengoeshere"}
23 }
24 );
25 });
26
27 bot.start(dpp::st_wait);
28
29 return 0;
30 }