Hi All,
I'm trying to pass urlrequest binding with "Date", "Authorization" to amazon s3 from flex 4.5 web application. However it's failed to connect and throws error as,
Error #2096: The HTTP request header Date cannot be set via ActionScript.
So, please tell me what i need to use or which flash player supports to add "Date" in header request.
I'm have taken code from http://as3awss3lib.googlecode.com/svn/trunk to upload files into amazon s3 using flex web app.
Below is the code for that,
private function getURLRequest(method:String, resource:String, contentType:String = null, hash:String = null, secure:Boolean = true):URLRequest
{
var protocol:String = (secure) ? "https" : "http";
var req:URLRequest = new URLRequest(protocol + "://" + AMAZON_ENDPOINT + resource);
/*req.cacheResponse = false;
req.useCache = false;*/
req.method = method;
var dateString:String = getDateString(new Date());
var dateHeader:URLRequestHeader = new URLRequestHeader("Date", dateString);
var authHeader:URLRequestHeader = new URLRequestHeader("Authorization", getAuthenticationHeader(method, dateString, resource, contentType, hash));
req.requestHeaders.push(dateHeader);
req.requestHeaders.push(authHeader);
return req;
}
private function getAuthenticationHeader(verb:String,
dateString:String,
resource:String,
contentType:String = null,
hash:String = null):String
{
return ("AWS " + this.accessKey + ":" + getAuthenticationString(verb, dateString, resource, contentType, hash));
}
private function getAuthenticationString(verb:String,
dateString:String,
resource:String,
contentType:String = null,
hash:String = null):String
{
var toSign:String = verb + "\n";
toSign += (hash != null) ? hash + "\n" : "\n";
toSign += (contentType != null) ? contentType + "\n" : "\n";
toSign += dateString + "\n" + resource;
var toSignBytes:ByteArray = new ByteArray();
toSignBytes.writeUTFBytes(toSign);
var hmacBytes:ByteArray = hmac.compute(secretAccessKeyBytes, toSignBytes);
return Base64.encodeByteArray(hmacBytes);
}
Please take reference of my previous post. Getting error in below method,
AWSS3.as - listObjects(...) - getURLStream() - throws as "Error #2007: Parameter type must be non-null.". Same code is working perfectly in AIR 2.6 and flash builder 4.5.
I want to do same in flash builder 4.5 using web.
use:
private function getDateString(d:Date):String
{
/*var dd:Date = new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
var ds:String = dateFormatter.format(dd);
return ds + " GMT";*/
var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.NONE);
var sd:String = df.format(d);
return escape(sd);
}
p.s. if you see an error message click "permit debugging" and paste the entire error message and indicate the first listed problematic line of code in from the error message.
your code is difficult to read but it doesn't appear that error message is related to the discussion in this thread.
in any case, if you want help with that click "permit debugging" and paste the entire error message and indicate the first listed problematic line of code in from the error message.
You cannot use Date and Authorization headers in Flash Player.
Adobe clearly states it in the docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/net/URLRequestHeader.html
In Flash Player and in Adobe AIR content outside of the application security sandbox, the following request headers cannot be used, and the restricted terms are not case-sensitive (for example,
Get,get, andGETare all not allowed). Also, hyphenated terms apply if an underscore character is used (for example, bothContent-LengthandContent_Lengthare not allowed):
Accept-Charset,Accept-Encoding,Accept-Ranges,Age,Allow,Allowed,Authorization,Charge-To,Connect,Connection,Content-Length,Content-Location,Content-Range,Cookie,Date,Delete,ETag,Expect,Get,Head,Host,If-Modified-Since,Keep-Alive,Last-Modified,Location,Max-Forwards,Options,Origin,Post,Proxy-Authenticate,Proxy-Authorization,Proxy-Connection,Public,Put,Range,Referer,Request-Range,Retry-After,Server,TE,Trace,Trailer,Transfer-Encoding,Upgrade,URI,User-Agent,Vary,Via,Warning,WWW-Authenticate,x-flash-version.
And there is no workaround.
North America
Europe, Middle East and Africa
Asia Pacific