flex-httpservice

由 syw00syw 撰写  http://blog.ityao.com/archives/629

mxml代码中 httpservice 组件,连接一php计算器


<s:Button click="this.hs.send();"/>
<fx:Declarations>
<s:HTTPService id="hs" url="http://127.0.0.1/cal.php" method="GET">
<s:request xmlns="">
<calculator>plus</calculator>
<param1>10</param1>
<param2>23</param2>
</s:request>
<s:fault>
<![CDATA[
trace("")
]]>
</s:fault>
<s:result>
<![CDATA[
trace(event.result.result.equals)
]]>
</s:result>
</s:HTTPService>
</fx:Declarations>

httpService组件,在as块中传入参数


var param:Object = {calculator:"minus",param1:"23",param2:"13"}
httpServ.send(param)

<mx:HTTPService id="httpServ">
<mx:resultFormat>text</mx:resultFormat>
<mx:url>http://127.0.0.1/cal.php</mx:url>
<mx:fault>Alert.show(event.toString(), event.type);</mx:fault>
</mx:HTTPService>

as代码中,使用httpservice类


public var httpservice:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
public var param:Object={calculator:"minus",param1:"23",param2:"13"};
public function send_data():void{
httpservice.url ="http://127.0.0.1/cal.php";
httpservice.method = "POST";
httpservice.addEventListener(ResultEvent.RESULT, resultHandler);
httpservice.addEventListener(FaultEvent.FAULT, this.HttpErrorHandle);
httpservice.send(param);
}

as代码中使用urlloader

public function Temp()
{
var url:String = "http://127.0.0.1/cal.php"
var urlVariables:URLVariables = new URLVariables();
urlVariables.decode("calculator=plus&param1=10&param2=22");
var request:URLRequest = new URLRequest(url);
request.data = urlVariables;
request.method = URLRequestMethod.POST

var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.TEXT
loader.addEventListener(Event.COMPLETE, onComplete)
loader.load(request);

}
public function onlistener(event:Event):void{
var xml:XML = new XML(event.target.data)

trace(xml..equals)
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值