简体   繁体   中英

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.

Steps I followed:

Created Event Hub, Generated SAS send token, Created Consumer group

Now in postman I am struggling to format the correct headers:

request I send:

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

2 headers:

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

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

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). The screenshot as below:

在此处输入图像描述

2 .Generate sas token, I create the sas token via powershell as per this link . Here is my powershell code and the returned sas token:

在此处输入图像描述

3 .In postman:

The request url should like this, remember add messages at the end: https://your_eventhub_namespace.servicebus.windows.net/your_eventhub_instance/messages

The headers:

Authorization: the sas token from step 2

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

Host(optional): your-eventhub-namespace.servicebus.windows.net

the screenshot as below, you can see the returned status code is 201 created:

在此处输入图像描述

And if you don't know how to set the message body, you can see my message in body in postman:

在此处输入图像描述

Please feel free to let me know if you still have any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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