简体   繁体   English

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

[英]POST data on Azure Event hub is failing

This is regarding Azure Event hub and I am trying to send data using a POST api call from POSTMAN to my Event hub.这是关于 Azure 事件中心,我正在尝试使用 POST api 调用从 POSTMAN 向我的事件中心发送数据。

Steps I followed:我遵循的步骤:

Created Event Hub, Generated SAS send token, Created Consumer group创建事件中心,生成 SAS 发送令牌,创建消费者组

Now in postman I am struggling to format the correct headers:现在在 postman 我正在努力格式化正确的标题:

request I send:我发送的请求:

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

2 headers: 2个标题:

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

and I get the error as 401 MalformedToken: Failed to parse simple web token我得到错误 401 MalformedToken: Failed to parse simple web token

What wrong am I doing in here?the refrence used is from https://docs.microsoft.com/en-us/rest/api/eventhub/Send-event?redirectedfrom=MSDN我在这里做错了什么?使用的参考来自https://docs.microsoft.com/en-us/rest/api/eventhub/Send-event?redirectedfrom=MSDN

Thanks in advance提前致谢

Please follow my steps as below:请按照我的步骤如下:

1 .After you create your eventhub namesapce and eventhub instance in azure portal -> in azure portal, nav to your eventhub namespace -> Shared access policies, click "Add" button to create a sas policy(here, I just select the Send privilege for sending purpose). 1 .After you create your eventhub namesapce and eventhub instance in azure portal -> in azure portal, nav to your eventhub namespace -> Shared access policies, click "Add" button to create a sas policy(here, I just select the Send privilege用于发送目的)。 The screenshot as below:截图如下:

在此处输入图像描述

2 .Generate sas token, I create the sas token via powershell as per this link . 2 .生成 sas 令牌,我按照此链接通过 powershell 创建 sas 令牌。 Here is my powershell code and the returned sas token:这是我的 powershell 代码和返回的 sas 令牌:

在此处输入图像描述

3 .In postman: 3.在 postman 中:

The request url should like this, remember add messages at the end: https://your_eventhub_namespace.servicebus.windows.net/your_eventhub_instance/messages请求 url 应该是这样的,记得在最后添加messageshttps://your_eventhub_namespace.servicebus.windows.net/your_eventhub_instance/messages

The headers:标题:

Authorization: the sas token from step 2授权:来自步骤 2 的 sas 令牌

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

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

the screenshot as below, you can see the returned status code is 201 created:截图如下,可以看到返回的状态码是 201 created:

在此处输入图像描述

And if you don't know how to set the message body, you can see my message in body in postman:如果您不知道如何设置消息正文,您可以在 postman 的正文中查看我的消息:

在此处输入图像描述

Please feel free to let me know if you still have any issues.如果您仍有任何问题,请随时告诉我。

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

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