-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpclient_async_test.cc
50 lines (38 loc) · 1.49 KB
/
httpclient_async_test.cc
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
#include "httpclient_async.hpp"
#include <iostream>
#include <thread>
auto main() -> int
{
auto url = "http://www.baidu.com?name=hello&age=18";
HttpClientAsync client;
// client.get("http://www.baidu.com", {}, [](const std::string &response) {
// std::cout << "GET response: " << std::endl;
// std::cout << response << std::endl;
// });
client.post(url, "hello world", {}, [](const std::string &response) {
std::cout << "POST response: " << std::endl;
std::cout << response << std::endl;
});
client.put(url, "hello world", {}, [](const std::string &response) {
std::cout << "PUT response: " << std::endl;
std::cout << response << std::endl;
});
client.del(url, {}, [](const std::string &response) {
std::cout << "DELETE response: " << std::endl;
std::cout << response << std::endl;
});
client.options(url, {}, [](const std::string &response) {
std::cout << "OPTIONS response: " << std::endl;
std::cout << response << std::endl;
});
client.patch(url, "hello world", {}, [](const std::string &response) {
std::cout << "PATCH response: " << std::endl;
std::cout << response << std::endl;
});
client.sendCustomRequest(url, "GET", "", {}, [](const std::string &response) {
std::cout << "Custom request response: " << std::endl;
std::cout << response << std::endl;
});
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;
}