0
votes

I'm trying to use cover art archive api. Cover Art Archive

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

but all I get is:

status: [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/"]

anyone can tell me what am I doing wrong?

Thx

edit 1: add: reqest.requestHeaders = new Array(new URLRequestHeader("accept", "application/json")); still no go...

2

2 Answers

1
votes

I don't think you are doing anything wrong. It seems like the HTTP request returns with a 307 TEMPORARY REDIRECT status :

$ 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, Flash URLLoader/URLRequest is not able to handle redirection for you ; the only solution I see is to issue HTTP requests by yourself using the Socket class, and grap the Location yourself! Obviously someone already tried it.

0
votes

Adding to Antoine's answer, AS3 url loader can follow redirects.

loader.followRedirects = true;

more details from adobes documentation.