2
我一直在嘗試使用.NET AWS Cloudfront API爲我的S3存儲桶創建簽名cookie,但每當我發送帶有創建的cookie的HTTP請求時,我都會得到「禁止」的結果。在這段代碼中有什麼我做錯了嗎?謝謝。在C#中使用AWS Cloudfront API創建簽名Cookie
CookiesForCannedPolicy cookies = AmazonCloudFrontCookieSigner.GetCookiesForCannedPolicy(
@"http://distribution123abc.cloudfront.net/*",
"KEYPAIRID",
new FileInfo(@"C:\bla\privatekey.pem"),
DateTime.Now.AddHours(1));
Uri target = new Uri(@"http://distribution123abc.cloudfront.net");
HttpWebRequest pleaseWork = (HttpWebRequest)WebRequest.Create(@"http://distribution123abc.cloudfront.net/files/test.txt");
if (pleaseWork.CookieContainer == null)
{
pleaseWork.CookieContainer = new CookieContainer();
}
pleaseWork.CookieContainer.Add(new Cookie(cookies.Signature.Key, cookies.Signature.Value) { Domain = target.Host });
pleaseWork.CookieContainer.Add(new Cookie(cookies.KeyPairId.Key, cookies.KeyPairId.Value) { Domain = target.Host });
pleaseWork.CookieContainer.Add(new Cookie(cookies.Expires.Key, cookies.Expires.Value) { Domain = target.Host });
try
{
WebResponse response = pleaseWork.GetResponse();
Console.WriteLine("Response content length: " + response.ContentLength);
}
catch(WebException e)
{
Console.WriteLine(e.Message);
}
有一次,我改變了IP範圍0.0.0.0/0這個完美工作,謝謝 – ScottieMc