-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathwebclient.cpp
More file actions
29 lines (26 loc) · 774 Bytes
/
webclient.cpp
File metadata and controls
29 lines (26 loc) · 774 Bytes
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
#include <iostream>
#include <memory>
#include <string>
#include <native/native.h>
using namespace native;
#include <fcntl.h>
int main() {
auto client = net::tcp::create();
client->connect("127.0.0.1", 8080, [=](error e){
client->write("GET / HTTP/1.1\r\n\r\n", [=](error e){
std::shared_ptr<std::string> response(new std::string);
client->read_start([=](const char* buf, ssize_t len){
if(len < 0) // EOF
{
std::cout << *response << std::endl;
client->close([](){});
}
else
{
response->append(std::string(buf, len));
}
});
});
});
return run();
}