c++ - http_listener casablanca 不从公共(public)方法绑定(bind)

标签 c++ visual-studio-2013 httplistener cpprest-sdk

如标题所示,我有一个可用的客户端服务器应用程序,但现在我尝试重新设计我的软件以使其更加优雅。所以我创建了一个 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/

相关文章:

Azure 辅助角色 - HttpListener - 错误 503。服务不可用

c++ - 从模板参数继承并在 C++ 中向上转换

c++ - 问题将值从一个数组转移到一个新数组

c++ - 如何检测库是否使用 XP 兼容性 (v120_xp)?

c# - Windows 8.1 ScriptNotify 不工作

jquery - HttpListener 问题

c# - 如何刷新 HttpListener 响应流?

c++ - 有效地计算体素数据的梯度

c++ - for 循环导致随机段错误 C++

jquery - 自从在 MVC 应用程序中通过 nuget 获取最新版本以来,jQuery.d.ts 中存在 100 多个错误