如何对 Azure 队列进行 REST 调用
How to make a REST call to an Azure Queue
我能够使用 SDK 对队列进行 C# 库调用。但是我无法对队列进行 REST 调用。
我该如何进行?任何代码示例将不胜感激。
官方文档中有例子:
Request:
POST https://myaccount.queue.core.windows.net/messages?visibilitytimeout=30&timeout=30 HTTP/1.1
Headers:
x-ms-version: 2011-08-18
x-ms-date: Tue, 30 Aug 2011 01:03:21 GMT
Authorization: SharedKey myaccount:sr8rIheJmCd6npMSx7DfAY3L//V3uWvSXOzUBCV9wnk=
Content-Length: 100
Body:
<QueueMessage>
<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText>
</QueueMessage>
https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-message
I am able to make a c# library call to a queue using SDK. However i am unable to make a Rest Call to the queue. How shall i proceed and Any code sample will be appreciated.
首先,this link 列出了 Azure 存储提供的用于处理消息队列的 REST 操作,请查看 link 以获取详细信息。
其次,这里是 create a queue under the given account 的示例请求,您可以像这样构造您的请求。
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture,
"https://{0}.queue.core.windows.net/{1}",
StorageAccount, queuename));
req.Method = "PUT";
req.Headers.Add("Authorization", AuthorizationHeader);
req.Headers.Add("x-ms-date", mxdate);
req.Headers.Add("x-ms-version", storageServiceVersion);
req.ContentLength = 0;
请参考以下代码和Authentication for the Azure Storage Services构造生成AuthorizationHeader.
的签名串
string canonicalizedHeaders = string.Format(
"x-ms-date:{0}\nx-ms-version:{1}",
mxdate,
storageServiceVersion);
string canonicalizedResource = string.Format("/{0}/{1}", StorageAccount, queuename);
string stringToSign = string.Format(
"{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}",
requestMethod,
canonicalizedHeaders,
canonicalizedResource);
请求看起来像这样。
我能够使用 SDK 对队列进行 C# 库调用。但是我无法对队列进行 REST 调用。
我该如何进行?任何代码示例将不胜感激。
官方文档中有例子:
Request:
POST https://myaccount.queue.core.windows.net/messages?visibilitytimeout=30&timeout=30 HTTP/1.1
Headers:
x-ms-version: 2011-08-18
x-ms-date: Tue, 30 Aug 2011 01:03:21 GMT
Authorization: SharedKey myaccount:sr8rIheJmCd6npMSx7DfAY3L//V3uWvSXOzUBCV9wnk=
Content-Length: 100
Body:
<QueueMessage>
<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText>
</QueueMessage>
https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-message
I am able to make a c# library call to a queue using SDK. However i am unable to make a Rest Call to the queue. How shall i proceed and Any code sample will be appreciated.
首先,this link 列出了 Azure 存储提供的用于处理消息队列的 REST 操作,请查看 link 以获取详细信息。
其次,这里是 create a queue under the given account 的示例请求,您可以像这样构造您的请求。
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture,
"https://{0}.queue.core.windows.net/{1}",
StorageAccount, queuename));
req.Method = "PUT";
req.Headers.Add("Authorization", AuthorizationHeader);
req.Headers.Add("x-ms-date", mxdate);
req.Headers.Add("x-ms-version", storageServiceVersion);
req.ContentLength = 0;
请参考以下代码和Authentication for the Azure Storage Services构造生成AuthorizationHeader.
的签名串string canonicalizedHeaders = string.Format(
"x-ms-date:{0}\nx-ms-version:{1}",
mxdate,
storageServiceVersion);
string canonicalizedResource = string.Format("/{0}/{1}", StorageAccount, queuename);
string stringToSign = string.Format(
"{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}",
requestMethod,
canonicalizedHeaders,
canonicalizedResource);
请求看起来像这样。