0
votes

I am using httpservice and once its called nothing happens. I don't get a result or an error? I have added various listeners but unable to catch any errors. Am i missing something?

    private function GetUsersServers():void
    {
        var serviceObj:HTTPService = new HTTPService();
        serviceObj.resultFormat = 'text';
        serviceObj.method = 'GET';
        serviceObj.useProxy = false;
        serviceObj.addEventListener(ResultEvent.RESULT, GetUsersServersResult);
        serviceObj.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        serviceObj.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
        serviceObj.addEventListener(Event.COMPLETE, onLoadComplete);
        serviceObj.url = '************************';

        var parameters:Object = new Object();
        parameters["Username"] = m_strUserSIP;

        LogAddItem( -1, "GetUsersServers Request - User = " + parameters.Username);
        serviceObj.send(parameters);
    }

    private function onLoadComplete(e:Event):void
    {
        var loader:URLLoader = URLLoader(e.target);
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "securityErrorHandler: " + loader.data);
    }

    // check for security error - probably crossdomain issue
    private function securityErrorHandler(event:SecurityErrorEvent):void {
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "securityErrorHandler: " + event);
    }

    public function onLoadError(e:IOErrorEvent):void {
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "Fault: " + e.text);
    }

    private function GetUsersServersResult(event:ResultEvent):void
    {
        LogAddItem( -1, "GetUsersServers Result Received..");
        var rawData:String = String(event.result);
        LogAddItem( -1, "GetUsersServersResult = " + rawData);
        InitContinue();
    }
1
I think you should listen for the fault event; I don't see any of the error events your listening for in the docs. - RIAstar

1 Answers

0
votes

The problem is most likely that you declare your HTTPService inside your function GetUsersServers(). When that function finishes, the variable holding the HTTPService no longer exists and is eligible for garbage collection.

Instead, if you declare the HTTPService as a member variable, the variable will exist throughout the lifetime of that class that it's in. So try something like this:

private var serviceObj:HTTPService;

private function GetUsersServers():void
{
    serviceObj = new HTTPService();
    ...
}