我似乎得到403:冲突
HTTP/1.1 403服务器无法验证请求。确保授权标头的值正确形成,包括签名。
发生这种情况时,我设置使用的HttpWebRequest.DefaultCachingPolicy
在App.config如下:
<system.net>
<requestCaching defaultPolicyLevel="Default" isPrivateCache="false">
<defaultHttpCachePolicy policyLevel="Default"/>
</requestCaching>
</system.net>
我这样做是因为我有旧的代码,我不控制被调用API将我提供的存储作为一个文件系统提供(每个文件最多58个相同的调用)。显然这并不理想。使用默认的HTTP风格缓存是我想要的行为,因为它会导致我的应用程序在修改文件时只下载文件。
这个问题似乎发生所有其他请求(例如,它出现时,该请求被缓存服务器检查,以查看是否在服务器内容已更改,将发生)。
失败的请求和成功的请求之间唯一的区别似乎是列入:
If-None-Match: "<a blob etag>"
If-Modified-Since: <a date>
我看过了.NET API的代码(我使用的)在github 1.7.1上,并假设它没有从SDK 1.6(我目前使用的)中更改,它应该可以正常工作。
任何帮助是非常赞赏
更新: 我已经写了一些摄制的代码,以帮助:
用途:.NET 4.0,Windows Azure的SDK 1.6
using System;
using System.Net;
using System.Net.Cache;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace AzureStorageProb
{
class Program
{
static void Main(string[] args)
{
const string accountKey = "<azure storage account key>";
const string account = "<azure storage account name>";
const string testBlob = "<blob path to test file>";
var cloudStorageAccount =
new CloudStorageAccount(
new StorageCredentialsAccountAndKey(account, accountKey),
useHttps: true);
var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
HttpWebRequest.DefaultCachePolicy =
new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
try
{
var blob = cloudBlobClient.GetBlobReference(testBlob);
blob.FetchAttributes();
blob.DownloadByteArray();
Console.WriteLine("First attempt worked!");
}
catch (StorageClientException ex)
{
Console.WriteLine(ex);
}
try
{
var blob = cloudBlobClient.GetBlobReference(testBlob);
blob.FetchAttributes();
blob.DownloadByteArray();
Console.WriteLine("Second attempt worked!");
}
catch (StorageClientException ex)
{
Console.WriteLine(ex);
}
Console.ReadKey();
}
}
}