-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
30 lines (27 loc) · 1.13 KB
/
example.cpp
File metadata and controls
30 lines (27 loc) · 1.13 KB
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
#include "http_client.hpp"
int main() {
HttpConnection httpConnection("google.com", 80);
httpConnection.openConnection();
HttpRequest request(
"GET", "/",
Headers({{"host", "google.com"},
{"user-agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) "
"Gecko/20100101 Firefox/91.0"}}));
auto response = httpConnection.sendRequest(request);
std::cout << "STATUS LINE: \n";
std::cout << "version: " << response.statusLine.version << std::endl;
std::cout << "code: " << response.statusLine.code << std::endl;
std::cout << "message: " << response.statusLine.message << std::endl;
std::cout << std::endl;
std::cout << "HEADERS: \n";
for (Headers::const_iterator it = response.headers.begin();
it != response.headers.end(); ++it) {
std::cout << it->first << " : " << it->second << std::endl;
}
std::cout << std::endl;
std::cout << "BODY: \n" << response.body << std::endl;
// std::size_t pos = response.body.find("\r\n");
// if (pos != std::string::npos)
// std::cout << "found at: " << pos << std::endl;
// std::cout << response.body.substr(pos) << std::endl;
}