c++ rest sdk http_listener 作为网络服务器

标签 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

我想在本地网络上使用 c++ rest sdk 作为服务器。

最佳答案

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

不工作是因为“localhost”拼写错误。

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

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

Listener.support(methods::GET, std::bind(&HandleGet, this, std::placeholders::_1));

和 HandleGet 函数(如果有 GET 请求)

HandleGet(http_request request)
{
   std::wcout << L"Received GET request" << std::endl;
}

所以在设置完成后,将您的网络浏览器指向该地址,您应该会看到输出。

此外,您可以将 ServerInit.open().wait()(开始监听)包装在 try/catch 中,看看它为什么不工作。

关于c++ rest sdk http_listener 作为网络服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20817648/

相关文章:

c# - 如何从 HttpListenerRequest 获取表单参数?

c++ - 错误 : failed to lock directory 'C:/Program Files/R/R-3.0.2/library' for modifying when installing RStan in Rstudio in Windows 7

c# - 套接字连接到局域网计算机失败?

c++ - 使用 Protocol Buffers 从文件中读取消息的问题

http - HTTP PUT 上下文中幂等性的含义?

c# - 将 URI 参数映射到参数对象的属性?

visual-studio - 用于创建任务的 VSTS REST Api

c# - 使用 Google Chrome 和 HTTPListener 获取 ProtocolViolationException

c++ - 如何将较大的数组缩小为较小的数组?

c++ - 调用函数时防止转换 int