Jack Murphy
Jack Murphy

Reputation: 3020

Actionscript 3 Read Response Content-Type

Is it possible to read the raw content-type of a web server response using the URLLoader class in Actionscript 3? We're receiving self descriping messages over http:

HTTP/1.1 200 OK 
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/x-protobuf; desc="http://domain.herokuapp.com/pb_message.desc"; messageType="SomeApp.YourCustomClass"; delimited=true; charset=utf-8
Date: Sat, 06 Apr 2013 23:16:07 GMT
Etag: "d27199cd1500953f6f4512c76bc58f28"
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
X-Rack-Cache: miss
X-Request-Id: 57e83c24a04a03959eeed4ca0d3ab961
X-Runtime: 0.044153
Content-Length: 13
Connection: keep-alive

The above example shows the object as type of protobuf, the desc property is a url to an object description, and the messageType is the application name with the corresponding object class.

I would like to be able to read the messageType paramater.

Upvotes: 1

Views: 1105

Answers (2)

Jack Murphy
Jack Murphy

Reputation: 3020

@Lee Burrows is correct. However, these seem to only be available for Air Applications. See: unable to get HTTP response code/headers in actionscript 3?

It would be great to be able to find a solution to this for the flash runtime

Upvotes: 0

user1901867
user1901867

Reputation:

You can retrieve response info by listening for HTTPStatusEvent on URLLoader:

myLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpHandler);

function httpHandler(event:HTTPStatusEvent):void
{
    for each (var object:Object in event.responseHeaders)
    {
    trace(object.name+" : "+object.value);
    }
}

Info is stored as Array of Objects, with name and value properties, in event.responseHeaders

Upvotes: 3

Related Questions