Fix stack use after scope error in client_example (#707)

This commit is contained in:
Martin Chang 2021-02-07 10:35:21 +08:00 committed by GitHub
parent 6542236b20
commit 0b5920a1f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,11 +4,12 @@
using namespace drogon;
int nth_resp = 0;
int main()
{
trantor::Logger::setLogLevel(trantor::Logger::kTrace);
{
int count = 0;
auto client = HttpClient::newHttpClient("http://www.baidu.com");
auto req = HttpRequest::newHttpRequest();
req->setMethod(drogon::Get);
@ -19,11 +20,10 @@ int main()
for (int i = 0; i < 10; ++i)
{
client->sendRequest(
req,
[&count](ReqResult result, const HttpResponsePtr &response) {
req, [](ReqResult result, const HttpResponsePtr &response) {
std::cout << "receive response!" << std::endl;
// auto headers=response.
++count;
++nth_resp;
std::cout << response->getBody() << std::endl;
auto cookies = response->cookies();
for (auto const &cookie : cookies)
@ -33,7 +33,7 @@ int main()
<< ":domain=" << cookie.second.domain()
<< std::endl;
}
std::cout << "count=" << count << std::endl;
std::cout << "count=" << nth_resp << std::endl;
});
}
}