Does someone can tell me how I can retrieve the reference of an HTTPService object after the HTTP request is done (success and fault)? Here is a simple Test Application that stores HTTP requests. When handling response ("httpResult" and "httpFault" functions), it seems impossible to retrieve which call succeed / failed.
This app output always "Call not found"
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init(event);">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
private var calls:Array;
private function init(event:FlexEvent):void{
calls = new Array();
// working HTTP Call
test('http://v4.ipv6-test.com/api/myip.php');
// not working HTTP Call
test('http://unknown.web.site.com/');
}
private function test(URL:String):void{
var service:HTTPService = calls[ calls.push(new HTTPService()) - 1];
service.url = URL;
service.method = 'GET';
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
service.send();
}
private function httpResult(e:ResultEvent):void{
for(var i:int = calls.length; i>=0; i--){
if(calls[i]==e.target || calls[i]==e.currentTarget){
trace('Successful HTTP call found #' + i);
return;
}
}
trace('Successful HTTP call not found :(');
}
private function httpFault(e:FaultEvent):void{
for(var i:int = calls.length; i>=0; i--){
if(calls[i]==e.target || calls[i]==e.currentTarget){
trace('Unsuccessful HTTP call found #' + i);
return;
}
}
trace('Unsuccessful HTTP call not found :(');
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
</s:WindowedApplication>