如何在IOErrorEvent上访问AS3 URLLoader返回数据 [英] How to access AS3 URLLoader return data on IOErrorEvent

查看:64
本文介绍了如何在IOErrorEvent上访问AS3 URLLoader返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为api写一个动作脚本库。我使用URLLoader对象从api加载数据。我遇到的问题是,只要api在400年代返回http状态,actionscript就会将其视为io错误。一切都很好,但是,在这种情况下,似乎无法访问任何返回的数据。因此,关于返回错误原因的所有有用的xml都会丢失。有没有办法解决?如果api返回错误时没有任何对开发人员有用的信息,这会让图书馆感到痛苦。谢谢您的帮助!

I'm writing an actionscript library for an api. I use a URLLoader object to load data from the api. The problem I'm having is that whenever the api returns an http status in the 400s, actionscript treats this as an io error. This is all find and good, however, it seems like there is no way to access any data that was returned if this is the case. Consequently, any helpful xml about the cause of the error that gets returned is lost. Is there any way around this? It makes the library kind of a pain, if there can't be any useful information for developers when the api returns an error. Thanks for any help!

推荐答案

如果发生400,您将无法访问数据。状态代码,但是,通过添加HTTP状态事件的侦听器。

You can't get access to the data in an event of a 400. You can get the status code, however, by adding a listener for the HTTP status event.

如果您控制后端代码,则有两种解决方法:

If you control the back-end code, there are a couple of workarounds:

一个选项是即使与Flash客户端通话时,即使在错误情况下,后端也能以200s响应,但是具有特殊的错误代码,因此客户端知道200响应实际上是一个错误。

One option is to have the backend respond with 200s even in error cases when talking to a flash client, but with a special error code so the client knows that the 200 response is actually an error.

另一个选择是在客户端上设置包含错误消息的cookie。 Flash本身不能访问Cookie,但是您可以使用ExternalInterface调用javascript来读取Cookie,或者可选地,客户端可以再次点击特殊的后端控制器,以读取Cookie并以错误消息作为响应。

Another option is to set a cookie on the client containing the error message. Flash can't natively access cookies, but you can call out to javascript using ExternalInterface to read the cookie, or optionally the client can do another hit to a special back-end controller that reads the cookie and responds with an error message.

这篇关于如何在IOErrorEvent上访问AS3 URLLoader返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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