无法在 actionscript 3 中获取 HTTP 响应代码/标头? [英] unable to get HTTP response code/headers in actionscript 3?

查看:36
本文介绍了无法在 actionscript 3 中获取 HTTP 响应代码/标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using URLLoader to POST to a server. The xml response from the server can respond with a 404 or a 403 (forbidden) error. However I am unable to get the response codes.

这是代码

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

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

status is always 0 regardless whether i return 200, 400, 404, 301, 500, etc...

有什么想法吗?

推荐答案

对于 AIR 仅您可以使用 httpResponseStatus.否则在没有 AIR 的 Flash/Flex 中你不能.

For AIR Only you can use the httpResponseStatus. Otherwise in Flash/Flex without AIR you cannot.

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

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

httpResponseStatus Event
Event Object Type: flash.events.HTTPStatusEvent HTTPStatusEvent.type property = flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS

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

Language Version : ActionScript 3.0 Runtime Versions : AIR 1.0 AIR 1.0

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

Dispatched if a call to the load() method attempts to access data over HTTP, and Adobe AIR is able to detect and return the status code for the request. Unlike the httpStatus event, the httpResponseStatus event is delivered before any response data. Also, the httpResponseStatus event includes values for the responseHeaders and responseURL properties (which are undefined for an httpStatus event. Note that the httpResponseStatus event (if any) will be sent before (and in addition to) any complete or error event.

这篇关于无法在 actionscript 3 中获取 HTTP 响应代码/标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆