8

PostMan如何联调SignalR WebSockets - 广州大雄

 1 year ago
source link: https://www.cnblogs.com/lgxlsm/p/17518719.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

我们在调试SignalR的时候,往往要写多一个客户端对接联调。其实,在过去的几个版本中,Postman 已经能够使用 WebSocket 连接连接到 SignalR 中心并发送和接收消息。

image

先观察浏览器是如何发送请求

image
image

在PostMan模拟请求

地址输入 wss://localhost:5001/chat

image
image

每一个消息最后还有一个结束符合 ,一定要记得,重要的事情说三遍!

{"protocol":"json","version":1}

image

发送此消息后,应会看到协议已接受的响应,并且你将开始从中心接收检测信号(类型:6)消息。伟大!现在您已连接,正在与 JSON 通信,并且已准备好发送或接收有效负载消息。

{"arguments":["daXiongFans","hello world"],"invocationId":"0","streamIds":[],"target":"send","type":1}

image

arguments":["daXiongFans","hello world"] 对应 Send(string name, string message)

    public class ChatHub : Hub
    {
        public async Task Send(string name, string message)
        {
            // Call the broadcastMessage method to update clients.
            await Clients.All.SendAsync("broadcastMessage", name, message);
        }
    }
image

数据发送成功,一个简单的PostMan如联调SignalR例子就是这样


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK