0

As title i have a client server application that works but now i try to redesign my software to be more elegant. So i created a Server class to create an http_listener and handle POST and GET method but after that it doesn't work anymore.In .h i have:

class Server

{ public: 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;

};

And in .c i have:

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 is defined in .c for test and it works but i'm not able to support POST method . I also tried different initialization of POST method like this:

m_listener.support(methods::GET, std::bind(&Server::handle_post, this, std::placeholders::_1));

but it doesn't work. Suggestions?

kenhero
  • 95
  • 2
  • 11

1 Answers1

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

looks more correct. However, is http_request copyable? If not, you will need to std::move it or pass by reference.

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142
  • Now It works ,could you tell me why my 2 "solutions" didn't work? I found them in many threads on stackoverflow without success. – kenhero May 03 '17 at 11:07
  • @kenhero I'm not familiar with the library you are using, but my first thought was that you were not passing a `this` in the first attempt. – Richard Hodges May 03 '17 at 11:44