2011-05-15 75 views
0

我的Flex應用程序在啓動時發送一些共享請求。有時需要花費很多時間來獲取它們,所以我將它們設置爲requestTimeout param至5秒。另外,我定義了一個處理故障事件的方法。我想在發生超時時重新發送請求。 雖然它不工作。你能看看代碼嗎?Flex HTTPService超時處理程序

protected function fatalErrorOccuredInfo(event:FaultEvent):void 
{ 
    // get the operation 
    var operation:mx.rpc.http.AbstractOperation = mx.rpc.http.AbstractOperation(event.target); 

    operation.url += "?t=" + new Date().getTime(); 
    operation.useProxy = false; 
    //this should resend a request that caused timeout 
    operation.send(); 

} 

我檢查新的請求是否在網絡監視器發送,但它並沒有顯示任何東西:-(

任何幫助將非常感激。

回答

0

WebService類有一個getOperation功能,返回的AbstractOperation

event.currentTarget.name

使用它,所以它將b Ë像

var operation:mx.rpc.http.AbstractOperation = myWebService.getOperation(event.currentTarget.name); 
operation.send(); 

我非常不知道,但如果operation.send()沒有得到結果的事件,您可能需要添加一個事件偵聽器ResultEvent.RESULT

+0

嗯。我不認爲我需要它,因爲在這種情況下操作不爲空,所以我使AbstractOperation充滿了我需要的所有數據。此外,我沒有得到任何錯誤(空指針或某事)。它只是不發送請求。你認爲你的解決方案會採取不同的行動? – 2011-05-15 11:35:47

+0

您是否嘗試過爲測試目的調用不同的Web服務?如果'操作'不爲空,那麼它應該工作。你有沒有放置一個斷點,看看'operation.send()'是否被實際執行? :) – 2011-05-15 11:38:56

+0

我還沒有嘗試過不同的web服務,但我已經做了一些調試,並且operation.send()實際上是執行的。我甚至把Alert.show()放在下一行,它總是出現。總結,它應該工作,但它不。廢話。 – 2011-05-15 11:42:09

0

一個問題,我看到的是這一行

operation.url += "?t=" + new Date().getTime(); 

每次您提出請求時,都會附加「?t =」+ new Date()。getTime();
雖然這不應該是你的主要問題,但它是一個問題。

private var operationURL:String = "someurl.com/page.php"; 
private function loadOperation():void{ 
    var operation:mx.rpc.http.AbstractOperation = mx.rpc.http.AbstractOperation(event.target); 
    operation.url = operationURL + "?t=" + new Date().getTime(); 
    operation.useProxy = false; 
    operation.send(); 
} 

private var retryCount:int = 0 
protected function fatalErrorOccuredInfo(event:FaultEvent):void{ 
    // don't want it stuck in an endless loading loop 
    // 10 count is more then enough 
    if(retryCount < 10){ 
    this.loadOperation(); 
    ++retryCount 
    } 
} 

此外,如果您安裝了FireFox,請獲取名爲HTTPfox的插件。
HTTPfox會告訴你所有來自瀏覽器的請求