本文介绍了AzureStorage Blob 服务器无法对请求进行身份验证.确保 Authorization 标头的值正确形成,包括签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows Azure Blob 中上传图像,但出现以下我无法处理的错误.

I'm trying to upload a image in Windows Azure Blob and I'm geting the following error which I can't handle.

服务器无法验证请求.确保 Authorization 标头的值包含签名正确形成.

当我尝试创建容器时发生错误.

The error occurs when I try to create a container.

   container.CreateIfNotExists()

这是我的代码

try
{
    Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    // Retrieve a reference to a container.
    CloudBlobContainer container = blobClient.GetContainerReference("samples");

    // Create the container if it doesn't already exist.
    // here is the error
    if (container.CreateIfNotExists())
    {
        container.SetPermissions(
            new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });
    }

    CloudBlockBlob blockBlob = container.GetBlockBlobReference("Image1");
    using (var fileStream = System.IO.File.OpenRead(@"Path"))
    {
        blockBlob.UploadFromStream(fileStream);
    }
}
catch (StorageException ex1)
{
    throw ex1;
}

我在代码中尝试了很多选项,但仍然出现错误.

I have tried a lot of options in my code but still getting the error.

推荐答案

正如其他人在评论中所建议的那样,我的 PC 的时间关闭了 1 小时.纠正它解决了问题.

My PC's time was off by 1 hour as suggested by others in the comments. Correcting it solved the problem.

这篇关于AzureStorage Blob 服务器无法对请求进行身份验证.确保 Authorization 标头的值正确形成,包括签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:50