Flex HTTPService Timeout handler
my flex application sends a few concurent requests on startup. Sometimes it takes a lot of time to fetch them all so I've set them requestTimeout
param to 5 secs. Additionally, I've defined a method that handles fault events. I'd like to resend a request when timeout occurs.
It doesn't work though. Could you take a look at the code?
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();
}
I ch开发者_JAVA百科eck whether a new request is sent in Network Monitor but it doesn't show anything :-(
Any help would be much appreciated.
WebService class has a getOperation function which returns an AbstractOperation.
Use it with event.currentTarget.name
So it would be something like
var operation:mx.rpc.http.AbstractOperation = myWebService.getOperation(event.currentTarget.name);
operation.send();
I am pretty not sure but if operation.send()
does not get to the result event, you might have to add an event listener for ResultEvent.RESULT
One problem I see is with this line
operation.url += "?t=" + new Date().getTime();
Every time you make a request you append "?t=" + new Date().getTime();
Although that shouldn't be your main issue it is a problem.
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
}
}
Also, If you have FireFox installed get an add-on called HTTPfox.
HTTPfox will show you all requests made from the browser
精彩评论