0
votes

I am trying to do a REST client using AS3, I am following this tutorial: http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b061afd5d7127074bbf44-8000.html

My code is the following:

import flash.events.Event; 
import flash.events.ErrorEvent; 
import flash.events.IOErrorEvent; 
import flash.events.SecurityErrorEvent; 
import flash.net.URLLoader; 
import flash.net.URLRequest; 
import flash.net.URLRequestMethod; 
import flash.net.URLVariables;

var url:String = "https://localhost:8443/restcomponent/tesimalex";

var requestor:URLLoader = new URLLoader(); 

function restServiceCall():void 
{ 
    trace("Calling REST Service...");
    //Create the HTTP request object 
    var request:URLRequest = new URLRequest( url ); 
    request.method = URLRequestMethod.GET; 

    //Add the URL variables 
  //  var variables:URLVariables = new URLVariables(); 
  //  variables.method = "test.echo"; 
  //  variables.api_key = "123456ABC"; 
  //  variables.message = "Able was I, ere I saw Elba.";             
  //  request.data = variables; 

    //Initiate the transaction 
    requestor = new URLLoader(); 
    requestor.addEventListener( Event.COMPLETE, httpRequestComplete ); 
    requestor.addEventListener( IOErrorEvent.IO_ERROR, httpRequestError ); 
    requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpRequestError ); 
    requestor.load( request ); 
} 

function httpRequestComplete( event:Event ):void 
{ 
    trace( event.target.data );     
} 

function httpRequestError( error:ErrorEvent ):void{ 
    trace( "An error occured: " + error.toString() );     
}

The only diference between my code and the one in the tutorial is the URL variables, that I commented, and the url used.

My REST service is a simple GET, if I type the url in the browser it shows me the JSON returned.

But in my AS3, when I call the method restServiceCall() it returns the following error:

Error opening URL 'https://localhost:8443/restcomponent/tesimalex?' An error occured: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: https://localhost:8443/restcomponent/tesimalex?"]

Anyone knows whats wrong?

1
The error #2032 is usually fired when Flash Player can not access to the used URL for any reason ( URL unavailable, blocked, ... ) so try to verify if your URL is accessible ...akmozo

1 Answers

0
votes

Ok... It was a security issue... I disabled SSL in my server and then my flash app managed to comunicate with my REST service.