drogon/examples/client_example/main.cc

28 lines
865 B
C++
Raw Normal View History

2018-07-24 09:24:23 +00:00
#include <drogon/HttpAppFramework.h>
#include <trantor/net/InetAddress.h>
#include <netdb.h>
#include <iostream>
#include <future>
int main()
{
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
2018-10-14 07:56:54 +00:00
auto client = HttpClient::newHttpClient("http://www.baidu.com");
auto req = HttpRequest::newHttpRequest();
2018-09-10 07:50:44 +00:00
req->setMethod(drogon::HttpRequest::kGet);
req->setPath("/s");
2018-10-14 07:56:54 +00:00
req->setParameter("wd", "weixin");
int count = 0;
for (int i = 0; i < 10; i++)
2018-09-10 07:50:44 +00:00
{
2018-10-14 07:56:54 +00:00
client->sendRequest(req, [&](ReqResult result, const HttpResponse &response) {
std::cout << "receive response!" << std::endl;
2018-09-10 07:50:44 +00:00
//auto headers=response.
count++;
2018-10-14 07:56:54 +00:00
std::cout << response.getBody() << std::endl;
std::cout << "count=" << count << std::endl;
2018-09-10 07:50:44 +00:00
});
2018-07-24 09:24:23 +00:00
}
2018-09-10 07:50:44 +00:00
HttpAppFramework::instance().run();
2018-07-24 09:24:23 +00:00
}