Azure queue delete rest API 返回 "No Content" while delete API 工作正常

Azure queue delete rest API returning "No Content" while delete API is working fine

我正在使用 rest delete API。它工作正常,但在每个成功响应中都会返回 No Content。我给了太多时间,但问题仍然存在。你能纠正我代码错误的地方吗?我搜索并实施了相同的方法,但我不知道我在什么时候犯了错误。

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;
        }

这是预期的行为。 Delete Message 操作应该是 return 没有内容。来自文档 here:

Status code

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

作为 的补充:删除消息不同于获取消息或使消息出队。您希望将 DELETE 调用到 return 是什么?

根据MDN (DELETE - responses)

If a DELETE method is successfully applied, there are several response status codes possible:

  • A 202 (Accepted) status code if the action will likely succeed but has not yet been enacted.
  • A 204 (No Content) status code if the action has been enacted and no further information is to be supplied.
  • A 200 (OK) status code if the action has been enacted and the response message includes a representation describing the status.