-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.cpp
74 lines (57 loc) · 2.07 KB
/
cli.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include "include/cprex/cprex.h"
void print(cpr::Response r)
{
if (cprex::StatusCode::Succeeded(r.status_code))
std::cout << "Response (" << r.status_code << "): '" << r.text << "'" << std::endl;
else
std::cout << "Response (" << r.status_code << "): Request failed" << std::endl;
}
int main()
{
cprex::Factory::PrepareSession("ipify", "https://api64.ipify.org");
// https://www.httpbin.org/
// https://httpstat.us/
// https://httpstat.us/200
// https://httpstat.us/Random/200,201,500-504
cprex::Factory::PrepareSession("rnd", "https://httpstat.us/Random/200,201,502-504");
cprex::Factory::PrepareSession("stat", "https://httpstat.us/");
{
std::cout << "ipify ######################" << std::endl;
auto ipify = cprex::Factory::CreateSession("ipify" /*, true*/);
// compile error (intentional), shall have a Path object
// auto r = ipify.Get();
// print(r);
auto r = ipify.Get(cprex::Path("/"));
print(r);
// compile error (intentional), must not use absolute URL
// r = ipify.Get(cpr::Url("https://api64.ipify.org"));
// print(r);
r = ipify.Get(cprex::Path("/"));
print(r);
r = ipify.Get("/");
print(r);
}
{
std::cout << "rnd ######################" << std::endl;
auto rnd = cprex::Factory::CreateSession("rnd");
for (int i = 0; i < 10; ++i)
{
std::cout << i << ": ";
auto r = rnd.Get("/");
print(r);
}
}
{
std::cout << "stat ######################" << std::endl;
auto stat = cprex::Factory::CreateSession("stat");
auto r = stat.Get(cprex::Path("/200"));
print(r);
r = stat.Get(cprex::Path("/201"));
print(r);
r = stat.Get(cprex::Path("/200"), cpr::Parameters {{"sleep", "5000"}});
print(r);
r = stat.Get("/200", cpr::Parameters {{"sleep", "5000"}});
print(r);
}
}