最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - testing websockets with postman new api - Stack Overflow

programmeradmin5浏览0评论

I am trying to get the postman api for websockets working, however I can't even make a connection:

When I try to make a connection

ws://localhost:5001/socket.io/

results in:

Error: Unexpected server response: 400 //for ws

//index.js
const port=5001
io.on("connection", (socket) => {
  //handshake and hydrate and test
  console.log("Client connected",socket.id);
  socket.on("test", (data)=>{
    console.log("test data is:",data)
    socket.emit("test", "server heard you!")
  });

what is the proper url string to connect to a socket.io/express/nodejs server?

I am trying to get the postman api for websockets working, however I can't even make a connection:

When I try to make a connection

ws://localhost:5001/socket.io/

results in:

Error: Unexpected server response: 400 //for ws

//index.js
const port=5001
io.on("connection", (socket) => {
  //handshake and hydrate and test
  console.log("Client connected",socket.id);
  socket.on("test", (data)=>{
    console.log("test data is:",data)
    socket.emit("test", "server heard you!")
  });

what is the proper url string to connect to a socket.io/express/nodejs server?

Share Improve this question asked May 24, 2021 at 18:07 altruiosaltruios 1,0832 gold badges15 silver badges32 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Socket.io supports polling and websocket transports.

To connect with Postman's WebSocket client, we have to explicitly set the WebSocket transport while connecting to a Socket.io server. This can be done by setting the transport=websocket parameter in the connection URL.

In your case, it will be: ws://localhost:5001/socket.io/?transport=websocket.

发布评论

评论列表(0)

  1. 暂无评论