azure - Azure 事件中心上的 POST 数据失败

标签 azure post azure-eventhub

这与 Azure 事件中心有关,我正在尝试使用 POST api 调用从 POSTMAN 将数据发送到我的事件中心。

我遵循的步骤:

创建了事件中心, 生成的 SAS 发送 token , 创建消费者组

现在在 postman 中我正在努力格式化正确的标题:

我发送的请求:

POST:  https://testeventhu.servicebus.windows.net/myhub 

2 个 header :

Content-Type : application/atom+xml;type=entry;charset=utf-8

Authorization:  SharedAccessSignature sig=kjheh/f6SqR8dIW2nRpGUCHuhdshss2KoCKo7Q6ozmY=&se=1571140739&skn=saspolicy&sr=https://testeventhu.servicebus.windows.net/myhub

我收到错误 401 MalformedToken: Failed to parse simple web token

我在这里做错了什么?使用的引用来自 https://learn.microsoft.com/en-us/rest/api/eventhub/Send-event?redirectedfrom=MSDN

提前致谢

最佳答案

请按照以下步骤操作:

1。在 azure 门户中创建 eventhub nameapceeventhub 实例后 -> 在 azure 门户中,导航到您的 eventhub命名空间 -> 共享访问策略,点击“添加”按钮创建一个sas策略(这里我只选择发送权限用于发送目的)。截图如下:

enter image description here

2.生成 sas token ,我按照此 link 通过 powershell 创建 sas token 。这是我的 powershell 代码和返回的 sas token :

enter image description here

3.在 postman 中:

请求网址应该像这样,记住在末尾添加messages:https://your_eventhub_namespace.servicebus.windows.net/your_eventhub_instance/messages

标题:

授权:步骤 2 中的 sas token

内容类型:application/atom+xml;type=entry;charset=utf-8

主机(可选):your-eventhub-namespace.servicebus.windows.net

截图如下,可以看到返回的状态码为201已创建:

enter image description here

如果你不知道如何设置消息正文,可以在postman中的body中看到我的消息:

enter image description here

如果您仍有任何问题,请随时告诉我。

关于azure - Azure 事件中心上的 POST 数据失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58395239/

相关文章:

node.js - Swift http post 请求将空正文发送到服务器

Azure - 每 10 分钟将文件复制到 FTP

azure - 从 LogicApp 使用 "Send a HTTP Request to DevOps"时获取身份验证错误

azure - 我收到模拟和真实 Azure 存储的错误请求 (400) 消息

javascript - 如何使用带有导入的 Body Parser 而不是必需的? ES6

php - 从远程表单接受发布数据是否安全?

azure - 如何使用 Azure EventHub 触发器返回到检查点?

c# - 带有 EventData 对象的 EventHubTrigger C#

azure - 登录.microsoftonline 已损坏

azure - 我们可以使用 OAuth 将数据放入 Azure 事件中心吗