问题描述
使用POST HTTP Request, 如何向Azure Storage Queue中写入Message呢?例如使用CURL发送POST指令是否可以呢?
CURL -H \”Content-Type: application/xml\” -X POST -d \”message body\” \”azure storage queue endpoint\”
问题解答
可以的,首先从Azure Storage Account中获取访问令牌,示例中使用的为SAS(Shared access signature : 共享访问签名)。然后直接发送POST请求。
第一步:获取SAS Token,进入Storage Account的Shared access signature 页面,选择“Queue” ,Allow resource type全部选择,然后根据所需要的操作设置Allow Permissions。
第二步:拼接 Endpoint。把上一步的SAS Token复制出来,与Queue的地址进行拼接:
完整的Endpoint URL为:
https://xxxxxxxx.queue.core.chinacloudapi.cn/testpostmethod/messages?sv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-10-16T15:10:22Z&st=2021-10-16T07:10:22Z&spr=https&sig=f%2Fktxxxxxc8qNeeAM9izhpAZttlpGivTLc%3D
第三步:发送POST 请求,消息体为XML格式<QueueMessage><MessageText>【message body】</MessageText></QueueMessage>
<QueueMessage><MessageText>Test the Azure Storage message 1016 -1</MessageText></QueueMessage>
- Postman VS CURL
- CURL 示例:
curl -H \"Content-Type: application/xml\"
-X POST
-d \"<QueueMessage><MessageText>Test the Azure Storage message 1016 - 9</MessageText></QueueMessage>\"
\"https://xxxxxxxx.queue.core.chinacloudapi.cn/testpostmethod/messages?sv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-10-16T15:10:22Z&st=2021-10-16T07:10:22Z&spr=https&sig=f%2FkttQxxxxxxxxAZttlpGivTLc%3D\"
-v
第四步:在Queue中查看数据
参考资料
Azure Storage Account Queue -Put Message :https://docs.microsoft.com/en-us/rest/api/storageservices/put-message
The
Put Message
operation adds a new message to the back of the message queue. A visibility timeout can also be specified to make the message invisible until the visibility timeout expires. A message must be in a format that can be included in an XML request with UTF-8 encoding. The encoded message can be up to 64 KiB in size for versions 2011-08-18 and newer, or 8 KiB in size for previous versions.
The
Put Message
request may be constructed as follows. HTTPS is recommended. Replacemyaccountwith the name of your storage account, and
myqueue
with the name of your queue: