0

我正在尝试使用封面艺术存档 api。封面艺术档案

var request:URLRequest = new URLRequest();
request.url = "http://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/";
request.method = URLRequestMethod.GET;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, loaderComplete);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

loader.load(request);

function loaderComplete(evt:Event):void {
    trace("Load Succcsed");
}

function ioErrorHandler(evt:IOErrorEvent):void {
    trace("io: " + evt + "\n");
}

function httpStatusHandler(evt:HTTPStatusEvent):void {
    trace("status: " + evt + "\n");
} 

但我得到的是:

状态:[HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0 responseURL=null]

io: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/ "]

谁能告诉我我做错了什么?

谢谢

编辑1:添加:reqest.requestHeaders = new Array(new URLRequestHeader("accept", "application/json")); 还是不行。。。

4

2 回答 2

1

我不认为你做错了什么。似乎 HTTP 请求返回307 TEMPORARY REDIRECT状态:

$ curl -v http://coverartarchive.org/release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/
* About to connect() to coverartarchive.org port 80 (#0)
*   Trying 72.29.166.157... connected
* Connected to coverartarchive.org (72.29.166.157) port 80 (#0)
> GET /release/76df3287-6cda-33eb-8e9a-044b5e15ffdd/ HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: coverartarchive.org
> Accept: */*
> 
< HTTP/1.1 307 TEMPORARY REDIRECT
< Date: Sun, 20 Jan 2013 21:09:02 GMT
< Content-Type: text/plain; charset=utf-8
< Connection: keep-alive
< Keep-Alive: timeout=20
< Content-Length: 86
< Location: http://archive.org/download/mbid-76df3287-6cda-33eb-8e9a-044b5e15ffdd/index.json
< Access-Control-Allow-Origin: *
< Server: CherryPy/3.1.2 WSGI Server
< 
See: http://archive.org/download/mbid-76df3287-6cda-33eb-8e9a-044b5e15ffdd/index.json
* Connection #0 to host coverartarchive.org left intact
* Closing connection #0

AFAIK,FlashURLLoader/URLRequest无法为您处理重定向;我看到的唯一解决方案是自己使用Socket该类发出 HTTP 请求,然后Location自己掌握!显然有人已经尝试过了

于 2013-01-20T21:19:33.083 回答
0

添加到 Antoine 的答案中,AS3 url 加载器可以遵循重定向。

loader.followRedirects = true;

更多详细信息来自adobes 文档

于 2015-02-13T22:40:05.023 回答