Azure 队列删除休息 API 返回 "No Content",而删除 API 工作正常

标签 azure api rest queue

我正在使用剩余删除 API。它工作正常,但在每次成功响应中都会返回无内容。我已经投入了太多时间,但问题仍然存在。您能纠正我的代码错误吗?我搜索并实现了相同的内容,但我不知道我在什么时候犯了错误。

public static string DeleteMessage(String queueName, string popreceipt, string messageid)
        {
            string requestMethod = "DELETE";
           
            String urlPath = String.Format("{0}/messages/{1}?popreceipt={2}", queueName, Uri.EscapeDataString(messageid), Uri.EscapeDataString(popreceipt));

            String storageServiceVersion = "2017-11-09";
            String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
            String canonicalizedHeaders = String.Format(
                    "x-ms-date:{0}\nx-ms-version:{1}",
                    dateInRfc1123Format,
                    storageServiceVersion);
            //String canonicalizedResource = String.Format("/{0}/{1}", StorageAccountName, urlPath);
            String canonicalizedResource = string.Format("/{0}/{1}/messages/{2}\npopreceipt:{3}", StorageAccountName, queueName, messageid, popreceipt);
            String stringToSign = String.Format(
                    "{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}",
                    requestMethod,
                    canonicalizedHeaders,
                    canonicalizedResource);
            String authorizationHeader = CreateAuthorizationHeader(stringToSign);

            Uri uri = new Uri("https://" + StorageAccountName + ".queue.azure.com/" + urlPath);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = requestMethod;
            request.Headers.Add("x-ms-date", dateInRfc1123Format);

            request.Headers.Add("x-ms-version", storageServiceVersion);

            request.Headers.Add("Authorization", authorizationHeader);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                Stream dataStream = response.GetResponseStream();

                return response.StatusCode.ToString();

            }
        }

public static String CreateAuthorizationHeader(String canonicalizedString)
        {
            String signature = String.Empty;

            using (HMACSHA256 hmacSha256 = new HMACSHA256(Convert.FromBase64String(StorageAccountKey)))
            {
                Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(canonicalizedString);
                signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
            }

            String authorizationHeader = String.Format(
                CultureInfo.InvariantCulture,
                "{0} {1}:{2}",
                "SharedKey",
                StorageAccountName,
                signature
            );

            return authorizationHeader;
        }

最佳答案

这是预期的行为。 删除消息操作应该不返回任何内容。来自文档here :

Status code

A successful operation returns status code 204 (No Content).

关于Azure 队列删除休息 API 返回 "No Content",而删除 API 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69345550/

相关文章:

azure - Azure 静态 Web 应用程序文件位于哪里?

azure - 如何将包含基本身份验证的Azure API应用程序导入API管理

api - 创建 Rails 5 API-Only 应用程序时使用什么进行用户注册?

rest - 是否可以在 REST 服务的 "post()"方法中提取原始消息正文字符串(即 XML 字符串或 JSON 字符串)?

multithreading - Spring Boot 应用程序可以同时处理多个请求吗?

ios - 如何在 Swift 中查看来自 HTTP GET 请求的服务器响应?

azure - 如何使用 appveyor 部署自定义 dll 以及 azure 函数

azure - Azure SQL 数据仓库的扩展能力如何?

api - 您曾经使用过的最好的API/框架/平台是什么?

windows - TNetSharingManager访问冲突问题