<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:HTTPService url="http://localhost/shishi.php" id="service" result="serviceResult(event)"
fault="serviceFault(event)" method="GET"
useProxy="false">
<mx:request xmlns="">
<id>{requestedId}</id>
</mx:request>
</mx:HTTPService>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var requestedId:String;
private var requestedName:String;
//trace the result of the service out
private function serviceResult(event:Event):void {
trace(service.lastResult.name);
}
// in the event that the service faults or times out
private function serviceFault(event:Event):void {
trace('broken service');
}
private function callService():void {
requestedId = input.text as String;
service.send();
}
]]>
</mx:Script>
<mx:TextInput id="input"/>
<mx:Button label="get user name" click="callService()"/>
<mx:Text text="{service.lastResult.id}"/>
<mx:Text text="{service.lastResult.name}"/>
<mx:Text text="{service.lastResult.age}"/>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
<mx:HTTPService url="http://localhost/shishi.php" id="service" result="serviceResult(event)"
fault="serviceFault(event)" method="GET"
useProxy="false">
<mx:request xmlns="">
<id>{requestedId}</id>
</mx:request>
</mx:HTTPService>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var requestedId:String;
private var requestedName:String;
//trace the result of the service out
private function serviceResult(event:Event):void {
trace(service.lastResult.name);
}
// in the event that the service faults or times out
private function serviceFault(event:Event):void {
trace('broken service');
}
private function callService():void {
requestedId = input.text as String;
service.send();
}
]]>
</mx:Script>
<mx:TextInput id="input"/>
<mx:Button label="get user name" click="callService()"/>
<mx:Text text="{service.lastResult.id}"/>
<mx:Text text="{service.lastResult.name}"/>
<mx:Text text="{service.lastResult.age}"/>
</mx:Application>
目测有用
忘记:shishi.php
<?php
$id_number = $_GET["id"];
$name = $_REQUEST["name"];
echo('<id>'.$id_number.'</id><name>OK</name><age>30</age>');
?>
本文介绍了一个使用 Flex 的 HTTPService 进行 GET 请求的具体实例。该实例通过向本地服务器发送请求来获取用户信息,并展示了如何定义请求参数、处理响应结果及错误情况。此外,还提供了一个简单的 PHP 脚本来模拟服务器端的响应。
1294

被折叠的 条评论
为什么被折叠?



