ActionScripts3 POST到URL问题

时间:2017-01-24 10:48:28

标签: actionscript-3

我正在尝试使用SMSPVA.com的API,当我将URL复制并粘贴到Firefox时它返回json值,但在Actionscripts3中输出错误的值。 我的代码不对。

我想在URL上发布数据并在输出窗口中使用“trace”打印响应。

import flash.net.*;

 function URLRequest_method() 
{
    var url:String = "http://smspva.com/priemnik.php?metod=get_balance&service=opt4&apikey=HPQjg2cyfY2KhkyAjJft";

    var request:URLRequest = new URLRequest(url);

    request.method = URLRequestMethod.GET;

    var urlLoader:URLLoader = new URLLoader();

    urlLoader.load(request);

    trace(request.data);

}

编辑:

import flash.net.*;
import flash.events.Event;

 function URLRequest_method():void
{
    var url:String = "http://smspva.com/priemnik.php?metod=get_balance&service=opt4&apikey=HPQjg2cyfY2KhkyAjJf";

    var request:URLRequest = new URLRequest(url);

    request.method = URLRequestMethod.GET;

    var urlLoader:URLLoader = new URLLoader();

    urlLoader.addEventListener(Event.COMPLETE, onLoaderComplete);    
    urlLoader.load(request);

}


 function onLoaderComplete(event:Event):void
{
    var urlLoader2:URLLoader = event.target as URLLoader ;
    trace(urlLoader2.data);
    trace(event.target.data.done);
}


URLRequest_method();

结果为真:“{”response“:”1“,”balance“:”0.00“}”

但警告也显示:“ReferenceError:错误#1069:在String上找不到属性并且没有默认值。”

出了什么问题?

1 个答案:

答案 0 :(得分:0)

Event.COMPLETE是异步操作,您应该监听 function URLRequest_method():void { var url:String = "http://smspva.com/priemnik.php"; var postParams:URLVariables = new URLVariables("metod=get_balance&service=opt4&apikey=HPQjg2cyfY2KhkyAjJf"); var request:URLRequest = new URLRequest(url); request.method = URLRequestMethod.GET; request.data = postParams; var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE, onLoaderComplete); urlLoader.load(request); } function onLoaderComplete( event:Event ):void { var urlLoader2:URLLoader = event.target as URLLoader; trace( urlLoader2.data ); var json:Object = JSON.parse( urlLoader2.data ); trace( "json.response = ", json.response ); trace( "json.balance = ", json.balance ); } 事件以获取加载的数据:

UPD:

{"response":"1","balance":"0.00"}

json.response =  1
json.balance =  0.00

输出:

POST

顺便说一句,您的终端不支持GET方法,只支持BindingList<T>