用存储的REST调用也是401错误~~

我按照教程使用REST调用BLOB的内容,也遇到的是401错误,这是什么情况?还有人也遇到了吗?

1个回答

您好,
请问您使用的是REST中的哪一个方法?据我所知,如果使用REST去调用blob中内容是,复杂的地方主要是在构造签名,首先我建议您先阅读下这篇文档:
https://msdn.microsoft.com/zh-cn/library/azure/dd179428.aspx
例如该方法:

 public void PutBlob(String containerName, String blobName)

{

    String requestMethod = "PUT";



    String urlPath = String.Format("{0}/{1}", containerName, blobName);



    String storageServiceVersion = "2012-02-12";



    String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);



    String content = "Andrew Carnegie was born in Dunfermline";

    UTF8Encoding utf8Encoding = new UTF8Encoding();

    Byte[] blobContent = utf8Encoding.GetBytes(content);

    Int32 blobLength = blobContent.Length;



    const String blobType = "BlockBlob";



    String canonicalizedHeaders = String.Format(

            "x-ms-blob-type:{0}\nx-ms-date:{1}\nx-ms-version:{2}",

            blobType,

            dateInRfc1123Format,

            storageServiceVersion);

    String canonicalizedResource = String.Format("/{0}/{1}", AzureStorageConstants.Account, urlPath);

    String stringToSign = String.Format(

            "{0}\n\n\n{1}\n\n\n\n\n\n\n\n\n{2}\n{3}",

            requestMethod,

            blobLength,

            canonicalizedHeaders,

            canonicalizedResource);

    String authorizationHeader = Utility.CreateAuthorizationHeader(stringToSign);



    Uri uri = new Uri(AzureStorageConstants.BlobEndPoint + urlPath);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

    request.Method = requestMethod;

    request.Headers.Add("x-ms-blob-typeobType);

    request.Headers.Add("x-ms-dateteInRfc1123Format);

    request.Headers.Add("x-ms-versionorageServiceVersion);

    request.Headers.Add("AuthorizationthorizationHeader);

    request.ContentLength = blobLength;



    using (Stream requestStream = request.GetRequestStream())

    {

        requestStream.Write(blobContent, 0, blobLength);

    }



    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

    {

        String ETag = response.Headers["ETag"];

    }

}


我们需要构造出shared key,同时注意header中的各个信息。
处理rest问题和调试rest错误时,我个人建议您可以使用fiddler去troubleshoot您的reqest请求,去解决问题。
同时,建议您参考这个博客:https://convective.wordpress.com/2010/08/18/examples-of-the-windows-azure-storage-services-rest-api/
Regards,
Will
如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问

xuzhoushi01
xuzhoushi01 谢谢,我试下~~
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐