Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

The HTTP request header Date cannot be set via ActionScript.

Guest
Aug 29, 2012 Aug 29, 2012

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.

TOPICS
ActionScript
6.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Nov 21, 2012 Nov 21, 2012

Sory for the late reply. I have used presigned url to download file from s3.

Translate
Community Expert ,
Aug 29, 2012 Aug 29, 2012

are you using a query string appended to your http request?  if so, copy and paste the request.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

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);

        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

Please someone guide me, possible way to acheive.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2012 Aug 29, 2012

where's getDateString?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

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";

        }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2012 Aug 29, 2012

escape that return.

and make sure your datetimeformatter has the correct params.  i believe DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.NONE) should work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

Let me try it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2012 Aug 29, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

Could see my previous post saying where i'm getting error. "Error #2007: Parameter type must be non-null.". Sory to troble you. Added escape(shortDate) as per your suggestions.

Message was edited by: grace-glory

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2012 Aug 30, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

Very sory, Error is coming before date.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 29, 2012 Aug 29, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 01, 2012 Sep 01, 2012

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/flash/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, and GET are all not allowed). Also, hyphenated terms apply if an underscore character is used (for example, both Content-Length and Content_Length are 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2012 Sep 12, 2012

Thanks, I have achieved different way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 15, 2012 Sep 15, 2012

Caan you explain how you resolve?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 21, 2012 Nov 21, 2012
LATEST

Sory for the late reply. I have used presigned url to download file from s3.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines