前台:
private function getText():void
{
var v:urlvariables = new urlvariables("name=jacky&age=35&address=HongKong China");
var r:URLRequest = new URLRequest();
r.url = "http://localhost:2222/FlexService/TextFrm.aspx";
r.method = URLRequestMethod.GET;
r.data = v;
var l:URLLoader = new URLLoader();
l.load(r);
l.addEventListener(Event.COMPLETE,txtCompleteHandler); //注册请求完成后 响应获取数据事件方法
labMsg.alpha = 1;
}
private function txtCompleteHandler(e:Event):void
{
var l:URLLoader = URLLoader(e.target);
var o:Object = URLUtil.stringToObject(String(l.data)); //使用URLUtil对将数据进行反序列化以方便使用
txtName.text = o.name;
txtAge.text = o.age;
txtAddress.text = o.address;
labMsg.alpha = 0;
}
后台:
protected void Page_Load(object sender,EventArgs e) { //获取URLResuest请求回的参数 返回数据用;分隔以方便Flex对数据进行序列化 string rs = String.Format("name={0};age={1};address={2}",Request.QueryString["name"], Request.QueryString["age"], Request.QueryString["address"]); Response.ClearContent(); Response.ContentType = "text/plain"; Response.Write(rs); //以文本形式返回数据 Response.End(); }