2017-05-03 35 views
0

由於標題我有一個客戶端服務器應用程序,但現在我嘗試重新設計我的軟件更優雅。所以,我創建了一個服務器類來創建一個http_listener和處理POST和GET方法,但之後它不工作anymore.In .hi有:http_listener卡薩布蘭卡不從公共方法綁定

class Server 

{ 市民: 服務器(){}

Server(utility::string_t url); 

pplx::task<void> open(); 
pplx::task<void> close(); 


void handle_post(web::http::http_request message); 

私人:

// Error handlers 
static void handle_error(pplx::task<void>& t); 
// HTTP listener 
web::http::experimental::listener::http_listener m_listener; 

};

而且在.CI有:

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)); 

,但它不工作。 建議?

回答

2
m_listener.support(methods::POST, [this](http_request request){ this->handle_post(request); }); 

看起來更正確。但是,http_request可複製?如果沒有,你將需要std::move它或通過引用。

+0

現在,它的工作原理,你能告訴我爲什麼我的2個「解決方案」不起作用嗎? 我發現他們在stackoverflow上的許多線程沒有成功。 – kenhero

+0

@kenhero我不熟悉你正在使用的圖書館,但我的第一個想法是,你沒有在第一次嘗試中傳遞「this」。 –

相關問題