是否可以从 Postman 调用 SignalR Hub [英] Is it possible to call a SignalR Hub from Postman

查看:18
本文介绍了是否可以从 Postman 调用 SignalR Hub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 SignalR 集线器的 ASP .Net Core 2.2 Web API.是否可以使用 Postman 调用其中一种方法(例如,SendMessageToAll)?问题是我只有 API - 没有前端 - 我需要测试.

I have an ASP .Net Core 2.2 Web API with a SignalR hub. Is it possible to call one of its methods (for example, SendMessageToAll) using Postman? The problem is that I only have the API - no frontend - and I need to test.

我尝试将 URl 放到我在 Postman 中的集线器 (api.mydomain.com/chatHub),但我不确定如何构建正文.我知道 SignalR 最好使用 WebSocket,但我不知道 PostMan 是否具有 WebSocket 功能.我相信如果 WebSockets 不可用,SignalR 也可以做 HTTP 请求,这是 Postman 可以做的.但我用什么身体?我应该使用 HTTP GET 还是 POST?

I tried putting the URl to my hub in Postman (api.mydomain.com/chatHub) but then I'm not really sure how to structure the body. I know SignalR uses WebSockets preferably, and I don't know if PostMan has WebSocket functionality. I believe SignalR can also do HTTP requests if WebSockets is not available, which is something Postman can do. But what body do I use? And do I use an HTTP GET or POST?

我在 Postman 中看到了一个人在使用这个身体的帖子:

I saw a post where the person was using this body in Postman:

{
    "Target": "SendMessageToGroup",
    "Arguments": [
        "groupA",
        "hello from server"
    ]
}

所以我尝试了相同的方法,但是当我在邮递员上单击发送"时,我的集线器的 SendMessageToGroup 方法没有被触发.

So I tried the same, but when I click "Send" on postman, the SendMessageToGroup method of my hub doesn't get triggered.

谢谢

推荐答案

不,postman 不支持 websocket.如果您只是将集线器注入控制器中,那么您可以使用集线器的方法并从邮递员内部的 http 请求调用它的公共方法.或使用其他应用程序:https://stackoverflow.com/a/59543405/4751073

No, postman does'nt support websocket. If you just inject your hub inside a controller then you can use hub's method and call it's public method from http request inside post man. Or use another app : https://stackoverflow.com/a/59543405/4751073

这篇关于是否可以从 Postman 调用 SignalR Hub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆