使用AS3调用REST服务时出现流错误

时间:2016-01-06 12:16:04

标签: rest actionscript-3

我正在尝试使用AS3做REST客户端,我正在学习本教程:http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b061afd5d7127074bbf44-8000.html

我的代码如下:

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() );     
}

我的代码与教程中的代码之间的唯一区别是我评论的URL变量和使用的URL。

我的REST服务是一个简单的GET,如果我在浏览器中键入url,它会向我显示返回的JSON。

但在我的AS3中,当我调用方法restServiceCall()时,它会返回以下错误:

  

打开网址“https://localhost:8443/restcomponent/tesimalex时出错?”一个   发生错误:[IOErrorEvent type =“ioError”bubbles = false   cancelable = false eventPhase = 2 text =“错误#2032:流错误.URL:   https://localhost:8443/restcomponent/tesimalex?“]

任何人都知道什么是错的?

1 个答案:

答案 0 :(得分:0)

好的......这是一个安全问题......我在服务器中禁用了SSL,然后我的Flash应用程序设法与我的REST服务通信。