C ++将sdk http_listener用作网络服务器

ami*_*min 2 c++ rest httplistener casablanca

如何配置http_listener侦听我的IP地址,以便网络上的其他计算机可以将请求发送到服务器?

http_listener listener(L"http://localhsot:9000"); // not working
http_listener listener(L"http://0.0.0.0:9000"); // run time error
http_listener listener(L"http://*:9000");       // run time error
Run Code Online (Sandbox Code Playgroud)

我想将c ++ rest sdk用作本地网络上的服务器。

小智 5

之所以 http_listener listener(L"http://localhsot:9000");

无法正常工作是因为“ localhost”拼写错误。

纠正拼写错误后,您应该可以将网络浏览器指向 http:// localhost:9000,您将收到请求。使用打印功能进行测试。

如前所述,请不要忘记为请求设置支持。

Listener.support(methods::GET, std::bind(&HandleGet, this, std::placeholders::_1));
Run Code Online (Sandbox Code Playgroud)

和HandleGet函数(如果GET请求)

HandleGet(http_request request)
{
   std::wcout << L"Received GET request" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

因此,完成此设置后,将您的Web浏览器指向该地址,您应该会看到输出。

另外,您可以将ServerInit.open().wait()(开始监听)包裹在中,try/catch以查看为什么它不起作用。