【发布时间】:2016-01-06 12:16:03
【问题描述】:
我正在尝试使用 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="Error #2032: Stream Error. URL: https://localhost:8443/restcomponent/tesimalex?"]
有谁知道怎么回事?
【问题讨论】:
-
错误 #2032 通常会在 Flash Player 因任何原因(URL 不可用、被阻止等)无法访问使用的 URL 时触发,因此请尝试验证您的 URL 是否可访问...
标签: rest actionscript-3