【问题标题】:Client progress polling with CPPRestSDK使用 CPPRESTSDK 进行客户端进度轮询
【发布时间】:2017-03-12 15:53:45
【问题描述】:
【问题讨论】:
标签:
c++
rest
asynchronous
casablanca
【解决方案1】:
首先你需要用一个 URL 来响应一个进度监听器
int progress = 0;
std::string progURL = "http://www.example.com/listener";
std::thread progList = std::thread{&ProgressListener, progURL, std::ref(progress)};
web::http::http_response response(web::http::status_codes::Accepted);
response.headers().add("Location", requURL);
request.reply(response);
然后启动一个线程,它允许您托管一个单独的侦听器。
void ProgressListener( std::string progURL, double &progress ){
web::http::experimental::listener::http_listener progListener(hostURL);
progListener.support(web::http::methods::GET, [&](web::http::http_request request){
web::http::http_response response;
response.set_status_code(web::http::status_codes::OK);
response.headers().add("Progress", progress); // You can call the header anything pretty much
request.reply(response);
}
}
然后您需要与您的客户端轮询该 url,并提取标头数据。