Connect Websocket with Poco libraries(将 Websocket 与 Poco 库连接)
问题描述
我正在尝试使用 Echo Test Websockethttp://www.appinf.com/docs/poco/Poco.Net.WebSocket.html" rel="nofollow noreferrer">Poco C++ 库.为此,我的代码应该设置 Websocket:
I am trying to connect to the Echo Test Websocket using the Poco C++ libraries. In order to do so here is my code which should set up the Websocket:
HTTPClientSession cs("echo.websocket.org");
HTTPRequest request(HTTPRequest::HTTP_GET, "/ws");
HTTPResponse response;
WebSocket* m_psock = new WebSocket(cs, request, response);
m_psock->close(); //close immidiately
但是它不起作用:我收到这样的错误消息:
However it does not work: I am getting an error message like this:
Poco::Exception: WebSocket Exception: Cannot upgrade to WebSocket connection: Not Found
有人可以帮忙吗?
推荐答案
未找到"错误是 HTTP 服务器返回的标准 HTTP 404 Not Found.这通常意味着您请求的资源不存在.
The 'Not Found' error is the standard HTTP 404 Not Found returned by the HTTP server. It generally means the resource you are requesting does not exist.
我通过将资源从 "/ws"
更改为 "/"
使您的代码正常工作:
I got your code to work by changing the resource from "/ws"
to "/"
:
HTTPRequest request(HTTPRequest::HTTP_GET, "/");
并添加以下行
request.set("origin", "http://www.websocket.org");
在创建新的 WebSocket
之前.我认为这是许多(或全部?)WebSocket 服务器所期望的头对.
before creating the new WebSocket
. I think it's a header pair that many (or all?) WebSocket servers expect.
这篇关于将 Websocket 与 Poco 库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 Websocket 与 Poco 库连接
基础教程推荐
- 分别使用%o和%x以八进制或十六进制格式显示整 1970-01-01
- C++输入/输出运算符重载 1970-01-01
- C++ #define 1970-01-01
- C++定义类对象 1970-01-01
- 明确指定任何或所有枚举数的整数值 1970-01-01
- end() 能否成为 stl 容器的昂贵操作 2022-10-23
- 使用scanf()读取字符串 1970-01-01
- C语言访问数组元素 1970-01-01
- 初始化变量和赋值运算符 1970-01-01
- C++按值调用 1970-01-01