Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 786 Bytes

README.md

File metadata and controls

25 lines (21 loc) · 786 Bytes

libevent_http

Example:

    //loop in another thread
    auto loop = http::EventLoop::New();
    loop->RunInBackground();
    auto resp = http::Get("http://www.baidu.com", loop).SetTimeout(1000).Execute();
    printf("%d:%lu\n", resp.GetResponseCode(), resp.GetBody().length);

    //callback
    http::Get("http://www.baidu.com")
        .AddHeader("Connection", "keep-alive")
        .SetTimeout(1000)
        .Execute([](http::Response&& r) {
                printf("%d:%lu\n", r.GetResponseCode(), r.GetBody().length);
        });

    //promise
    std::promise<http::Response> p;
    auto future = http::Get("http://www.baidu.com").SetTimeout(1000).Execute(p);
    auto resp = future.get();
    printf("%d:%lu\n", resp.GetResponseCode(), resp.GetBody().length);