我似乎得到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();
}
}
}