如标题所示,我有一个可用的客户端服务器应用程序,但现在我尝试重新设计我的软件以使其更加优雅。所以我创建了一个 Server 类来创建一个 http_listener 并处理 POST 和 GET 方法,但之后它就不再工作了。在 .h 中我有:
class Server
{ 民众: 服务器(){}
Server(utility::string_t url);
pplx::task<void> open();
pplx::task<void> close();
void handle_post(web::http::http_request message);
私有(private):
// Error handlers
static void handle_error(pplx::task<void>& t);
// HTTP listener
web::http::experimental::listener::http_listener m_listener;
};
在 .c 中我有:
Server::Server(utility::string_t url) : m_listener(url)
{
m_listener.support(methods::POST, [this](http_request request){return Server::handle_post(request); });
m_listener.support(methods::GET, handle_get);
handle_get 在 .c 中定义用于测试,它可以工作,但我无法支持 POST 方法。 我也试过像这样对 POST 方法进行不同的初始化:
m_listener.support(methods::GET, std::bind(&Server::handle_post, this, std::placeholders::_1));
但它不起作用。 有什么建议吗?
最佳答案
m_listener.support(methods::POST, [this](http_request request){ this->handle_post(request); });
看起来更正确。但是,http_request
是可复制的吗?如果不是,您将需要 std::move
它或通过引用传递。
关于c++ - http_listener casablanca 不从公共(public)方法绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43749751/