httpservice request传参数的几种方式

syw00syw 撰写  

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)
		}

发表评论

你必须在 登录 后才能发表评论.