简体   繁体   English

cURL 请求节点上的 Socket IO (Express)

[英]cURL request for Socket IO on Node (Express)

We want to be able to test the Socket IO connection on our Node (Express) backend without using the SocketsIOClient (which does work!), using cURL (or another command line tool).我们希望能够在不使用 SocketsIOClient(它确实有效!)、使用 cURL(或其他命令行工具)的情况下,在我们的 Node (Express) 后端测试 Socket IO 连接。

I found the following:我发现了以下内容:

curl --verbose -i -N -H "Upgrade: websocket" -H "Connection: Upgrade" http://<API_URL>:<PORT>

However, this does not work.但是,这不起作用。 Even when using http://localhost:3000 and running locally, it did not work.即使使用http://localhost:3000并在本地运行,它也不起作用。 This is the response:这是回应:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.64.1
> Accept: */*
> Upgrade: websocket
> Connection: Upgrade
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
* Closing connection 0
npx wscat -c ws://localhost:3000/socket.io/\?transport=websocket

This worked for me to establish WebSockets connection这对我建立 WebSockets 连接有用

If the last line of output is < 40 , "event-name" event with "new message" message can be emitted with the following command如果输出的最后一行< 40 ,则可以使用以下命令发出带有"new message"消息的"event-name"事件

> 42["event-name","new message"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM