httpservice request传参数的几种方式

来源:互联网 发布:js的二维数组赋值 编辑:程序博客网 时间:2024/06/05 17:43

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

 

帮助

1234567891011121314151617181920
<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块中传入参数

 

帮助

12345678
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类

 

帮助

123456789
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

 

帮助

1234567891011121314151617181920
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)        }
From - http://blog.ityao.com/archives/629