drogon/examples/client_example/main.cc

42 lines
1.3 KiB
C++
Raw Normal View History

2018-10-18 07:54:57 +00:00
#include <drogon/drogon.h>
2018-07-24 09:24:23 +00:00
#include <iostream>
#include <future>
using namespace drogon;
2018-07-24 09:24:23 +00:00
int main()
{
2019-05-18 12:39:57 +00:00
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
2018-09-10 07:50:44 +00:00
{
2019-02-02 03:34:00 +00:00
int count = 0;
2018-11-17 09:33:05 +00:00
auto client = HttpClient::newHttpClient("http://www.baidu.com");
auto req = HttpRequest::newHttpRequest();
req->setMethod(drogon::Get);
req->setPath("/s");
req->setParameter("wd", "weixin");
2019-11-21 03:27:47 +00:00
for (int i = 0; i < 10; ++i)
{
2019-05-18 12:39:57 +00:00
client->sendRequest(
req,
[&count](ReqResult result, const HttpResponsePtr &response) {
std::cout << "receive response!" << std::endl;
// auto headers=response.
2019-11-21 03:27:47 +00:00
++count;
2019-05-18 12:39:57 +00:00
std::cout << response->getBody() << std::endl;
auto cookies = response->cookies();
for (auto const &cookie : cookies)
{
std::cout << cookie.first << "="
<< cookie.second.value()
<< ":domain=" << cookie.second.domain()
<< std::endl;
}
std::cout << "count=" << count << std::endl;
});
}
2018-07-24 09:24:23 +00:00
}
2018-09-10 07:50:44 +00:00
app().run();
2018-10-18 07:54:57 +00:00
}