2011-04-05 166 views
2

使Flash无法识别有效的HTTP响应代码(207)有些困难。奇怪的是,这似乎只发生在FireFox到目前为止..在Chrome中工作正常。Flash和HTTP状态码207

下面是生成以下错误的代码。它似乎在FlashBug中返回HTTP状态0 ..必须在Chrome中以不同的方式处理?有什么办法仍然可以得到答复机构吗?

没有我做的似乎能够让我在这种情况下的响应正文。 :(

// Initiate a call to a Patron URL 
    private function callPatron(url:String, callback:Function) { 
     trace("Calling Patron"); 
     _loader.addEventListener(Event.COMPLETE, function(e:Event) { callback(parseResponse(e)) }); 
     _loader.addEventListener(IOErrorEvent.IO_ERROR, gotError); 
     _loader.addEventListener("httpResponseStatus", onStatus); 
     _loader.addEventListener(ProgressEvent.PROGRESS, progressHandler); 
     _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);   
     _loader.load(new URLRequest(url)); 
    } 

    private function progressHandler(event:ProgressEvent) { 
     trace("Progresso"); 
    } 

    private function onStatus(event:HTTPStatusEvent) { 
     trace('Got HTTP status: ' + event.status); 
     trace(event.toString()); 
    } 

    private function gotError(event:IOErrorEvent) { 
     trace('IOError: ' + event.text); 
     var loader:URLLoader = URLLoader(event.target); 
     trace(loader.content); 
     trace('WORD.'); 
    } 

    // Decode a Patron response event and return the parsed object 
    public function parseResponse(event:Event):Object { 
     trace("Got a Patron response"); 
     var loader:URLLoader = URLLoader(event.target); 
     return JSON.decode(loader.data); 
    } 

..和输出:

Initializing 
Calling Patron 
Got HTTP status: 0 
[HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0 responseURL=null] 
IOError: Error #2032: Stream Error. URL: http://www.zappos.com/api/Product?key=5f25a02d8015e05ba3874e0b45be0379fe8b3c21&styleId=["1377484","1312254","269758","1519409","1325534","1152368"]&includes=["description","productRating","styles","thumbnailImageUrl"] 
WORD. 

回答

3

不幸的是,你不会得到全套的Flash中的HTTP响应代码,在所有浏览器的Flash播放器不具备它自己的HTTP处理(当作为浏览器插件运行时),而是使用托管浏览器进行HTTP调用,并且在浏览器和插件之间的某个位置,某些响应代码和标头等信息会减少。由Arc90(Readability公司背后的公司)讨论这个问题,它是一个按照我的理解,它们的解决方案在所有情况下都不起作用,但它可能会让您对问题有所了解:http://lab.arc90.com/2008/03/25/flex-as3-library-restservice/

+0

谢谢,我最终尝试使用as3httpclient - 一个类似的基于套接字的客户端。但它看起来不像基于网络的闪光灯那么热。 :/ – makenai 2011-04-06 06:18:18