读取 URLLoader 的服务器错误消息

发布于 2024-09-05 04:40:13 字数 1021 浏览 5 评论 0原文

我有一个带有以下代码的 URL 加载器:

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();

    var url:String = getPath();
    // Adds time to prevent caching
    url += "&time=" + new Date().getTime(); 

    request.url = url;
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
    _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);

    _loader.load(request);
}

我的问题是这个请求可能是错误的,因此服务器会给我一个 400 Bad Request,并带有一条解释错误的消息。如果Event.COMPLETE,我可以在事件的“数据”字段中看到从服务器返回的一些消息(响应),但是如果调用onGetUploadURLError或getHttpStatus,它只是说错误代码是400但不显示我与它相关的消息。

getHttpStatus 中的“data”字段未定义,而 onGetUploadURLError 中的“data”字段为“”。 相反,在 getBaseURL 中,我得到: {"ResponseMetadata":{...}} 我检查过,确实在浏览器中收到了针对错误请求的类似响应,但我看不到它。

知道如何才能收到消息吗?

非常感谢, 鲁迪

I have an URL loader with the following code:

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();

    var url:String = getPath();
    // Adds time to prevent caching
    url += "&time=" + new Date().getTime(); 

    request.url = url;
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);
    _loader.addEventListener(IOErrorEvent.IO_ERROR, onGetUploadURLError);
    _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, getHttpStatus);

    _loader.load(request);
}

My problem is that this request might be wrong, and so the server will give me a back a 400 Bad Request, with a message to explain the error. If the Event.COMPLETE, I can see some message (a response) back from the server in the "data" field of the Event, but if onGetUploadURLError or getHttpStatus is called, it just says that the error code is 400 but does not show me the message associated with it.

The "data" field is undefined in getHttpStatus and it is "" in onGetUploadURLError.
On the contrary, in getBaseURL, I get: {"ResponseMetadata":{...}}
I checked and I do get a similar response in my browser for a wrong request, but I cannot see it.

Any idea how I can please get the message?

Thank you very much,
Rudy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-09-12 04:40:13

Flash 不能很好地处理 HTTP 状态代码。这是博客文章< /a> 一位 Adob​​e 员工评论说问题实际上是插件限制。 Adobe 员工指出有一个库可以通过套接字使用 AS3 进行 HTTP 请求,但我怀疑这会效率很高(与将插件请求发送给浏览器相比)。

我参与过的所有项目的标准做法是始终发送 200 OK 并在消息中添加 error 键。

编辑:另请参阅此错误,这正是您的问题问题。

Flash does not handle HTTP status codes very well. Here is a blog post with comments from an Adobe employee saying the problem is actually the plug-in limitations. The Adobe employee points to a library for doing HTTP requests using AS3 through sockets but I doubt that would be highly efficient (compared to having the plugin-in hand requests off to the browser).

Standard practice on all projects I have ever worked on was to always send a 200 OK and add a error key onto the message.

edit: also see this bug which is exactly your issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文