Code: Select all
cobalt::promise HttpsClient::GET(const std::string &url){
co_return co_await asio_impl.GET(url);
}
< /code>
Die ASIO impl funktioniert: < /p>
asio::awaitable HttpsClientImpl::GET(std::string_view url, beast::http::fields headers = {})
{
auto data = "";
auto [error, http_response] = co_await redirector_.do_session(http::verb::get, url, headers, data, ssl_ctx_);
if (!error) {
FinalResult fr = http_response->body();
co_return fr;
}
else {
co_return FinalResult();
}
}
< /code>
Hier ist, wie ich es mir vorgestellt habe, es in der Benutzeroberfläche aufzurufen. Tatsächlich ist hier auch ein [url=viewtopic.php?t=20324]Problem[/url] mit Co_AWAIT
zurückgeben
Code: Select all
QObject::connect(button, &QPushButton::clicked, &w, [&](){
std::string url = "https://microsoftedge.github.io/Demos/json-dummy-data/64KB.json";
label->setText("Getting response...");
FinalResult result = co_await client.GET(url);
label->setText("Response ready!");
text->setPlainText(QString::fromStdString(result));
});