1

是否可以使用 Actionscript 3 中的 URLLoader 类读取 Web 服务器响应的原始内容类型?我们通过 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

上面的示例将对象显示为 protobuf 的类型,desc 属性是对象描述的 url,messageType 是具有相应对象类的应用程序名称。

我希望能够阅读 messageType 参数。

4

2 回答 2

3

您可以通过侦听 URLLoader 上的 HTTPStatusEvent 来检索响应信息:

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

信息在 event.responseHeaders 中存储为具有名称和值属性的对象数组

于 2013-04-07T01:30:43.157 回答
0

@Lee Burrows 是正确的。但是,这些似乎仅适用于 Air 应用程序。请参阅:无法在 actionscript 3 中获取 HTTP 响应代码/标头?

能够为闪存运行时找到解决方案将是很棒的

于 2013-04-07T21:16:04.750 回答