-
Notifications
You must be signed in to change notification settings - Fork 37
Client Documentation
hij1nx edited this page Oct 3, 2014
·
7 revisions
The following code examples assume you are using using namespace http;
and using namespace std;
for the sake of readability. The practice of using namespaces like this in your code is not recommended.
You can construct a client by passing either a url
or options
struct. In either case, a callback is required which will yield an instance of the Response
class.
For simplicity, you can just pass a url in the form of a string to construct a client instance.
Client client("http://google.com", [](auto& res) {
cout << res.body << endl;
})
client.end();
Options opts;
opts.host = "google.com";
opts.port = 80;
opts.url = "/";
opts.method = "GET";
Client client(opts, [](auto& res) {
cout << res.body << endl;
});
Write a buffer or string to the body of the request.
client.write([buffer|string]);
Will finish writing the request.
client.end([buffer|string]);
Tells you how many bytes have been read in the lifetime of the client instance.