无法在动作脚本3中获取HTTP响应代码/标头?

use*_*078 5 http httpresponse actionscript-3

我正在使用URLLoader来POST到服务器.来自服务器的xml响应可以响应404或403(禁止)错误.但是我无法获得响应代码.

这是代码

  var urlString:String = "some url";
  var urlRequest:URLRequest = new URLRequest(urlString);
  var loader:URLLoader = new URLLoader();
  loader.addEventListener( Event.COMPLETE, setXMLData );
  loader.addEventListener( IOErrorEvent.IO_ERROR, ioHandler );
  loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, httpStatusHandler );

//...

public function httpStatusHandler(evt:HTTPStatusEvent):void {
    trace("status is " + evt.status);
}
Run Code Online (Sandbox Code Playgroud)

无论我是否返回200,400,404,301,500等,状态始终为0 ...

有任何想法吗?

Tod*_*ses 3

仅对于 AIR,您可以使用 httpResponseStatus。否则,在没有 AIR 的 Flash/Flex 中,您不能这样做。

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#event:httpResponseStatus

httpResponseStatus 事件
事件对象类型:flash.events.HTTPStatusEvent HTTPStatusEvent.type 属性 = flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS

语言版本:ActionScript 3.0 运行时版本:AIR 1.0 AIR 1.0

如果对 load() 方法的调用尝试通过 HTTP 访问数据,并且 Adob​​e AIR 能够检测并返回请求的状态代码,则进行调度。与 httpStatus 事件不同,httpResponseStatus 事件在任何响应数据之前传递。此外,httpResponseStatus 事件还包括responseHeaders 和responseURL 属性的值(对于httpStatus 事件未定义这些值)。请注意,httpResponseStatus 事件(如果有)将在任何完成或错误事件之前(以及除此之外)发送。