204禁止天蓝色存储

时间:2015-02-05 08:23:27

标签: azure

以下请求成功:

HEAD https://ascendxyzweutest.blob.core.windows.net/b89e6c6cdde0421996a7ba47fcb57184-workset?restype=container HTTP/1.1
User-Agent: WA-Storage/4.3.0 (.NET CLR 4.0.30319.0; Win32NT 6.2.9200.0)
x-ms-version: 2014-02-14
x-ms-client-request-id: b566c59d-b8ac-4b7e-9cfc-820337971cc9
x-ms-date: Thu, 05 Feb 2015 00:59:17 GMT
Authorization: SharedKey ascendxyzweutest:+KdHX5Bewm5uP4lPHUtEcCv79tC3dQK28evyg1trOlw=
Host: ascendxyzweutest.blob.core.windows.net
Connection: Keep-Alive

回复:

HTTP/1.1 404 The specified container does not exist.
Transfer-Encoding: chunked
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 2fa4a112-0001-0010-7b56-b4eb01000000
x-ms-version: 2014-02-14
Date: Thu, 05 Feb 2015 00:59:23 GMT

以上示例来自teh .net Storage Library

然后我正在尝试使用WebRequest。

HEAD https://ascendxyzweutest.blob.core.windows.net/ccf2a083affa4e6c8d489fe1b2f0d32a-workset?restype=container HTTP/1.1
x-ms-version: 2014-02-14
x-ms-client-request-id: 92afdcaf-5afe-4f6a-914e-4850a4f0bd1d
x-ms-date: Thu, 05 Feb 2015 01:01:56 GMT
Authorization: SharedKey ascendxyzweutest:LRoIdLp0m4nR0XhRlcTT7gyyi6zYJhGg3fHmXKemPVc=
Host: ascendxyzweutest.blob.core.windows.net
Connection: Keep-Alive

回复:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Transfer-Encoding: chunked
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 61b7318c-0001-001c-6cc4-b6edcd000000
Date: Thu, 05 Feb 2015 01:02:22 GMT

此处的所有其他帖子都表明其x-ms-date字段关闭时间超过15分钟。我从同一台机器上执行了这两个,分离时间为5分钟,这也是请求标题中的内容。所以我不相信时间已经结束。

我正在使用Azure Storage SDK中的内容签署请求。

public Task SignRequestAsync(HttpWebRequest request, string tenantid, string container)
        {
            var a = new SharedKeyAuthenticationHandler(SharedKeyCanonicalizer.Instance, account.Credentials, account.Credentials.AccountName);
            a.SignRequest(request,null);
            return Task.FromResult(0);

        }

关于什么可能出错的任何指示。

1 个答案:

答案 0 :(得分:0)

Gaurav Mantri协助我解决了这个问题。问题是由于设置了一些在计算签名时使用的标头,但在执行reqest时省略了这些标头。 Content-Length设置为0等。

  

当您检查容器是否存在时,问题出在您的“HEAD”请求上。基本上在计算签名时,您传递的是“Content-Length”(即使它的值为0),但它不会作为请求头传入。因此,您的签名不匹配,您会收到403错误。如果我注释掉你设置请求的“ContentLength”属性的代码,那么你的“HEAD”请求会成功(但是你的PUT请求会失败)。