访问服务器端数据
有时你要连接的服务并非是SOAP风格的。其他常用的框架可以结合使用HTTP Get和Post方法来返回数据。使用<mx:HTTPService>标签可以让你访问这种类型的WEB服务。
使用HTTP Post和Get方法操作的WEB服务可以理解为REST服务。在很多情况下,使用HTTP Post方法。使用HTTP Web服务的一个明显的好处是你可以传递比使用SOAPWeb服务时更少的数据。
Adobe Flexx 数据访问组件使用远程过程调用(RPC)来与服务器环境交互,例如PHP,Adobe ColdFusion,和Microsoft ASP.NET,来为Flex程序提供数据,以及将数据传递给后台的数据源。 连接到一个HTTP Web服务可以很容易的使用<mx:HTTPSevice>。<mx:HTTPService>有着类似<mx:WebService>和<mx:HTTPService>标签的属性,且具有falt和result时间供你监听和处理,如下所示:
<mx:HTTPService id="yahooHTTPService"
url="http://search.yahooapis.com/WebSearchService/V1/webSearch"
method="GET"
makeObjectsBindable="true" result="httpServiceResult(event)"
fault="httpServiceFault(event)" showBusyCursor="true">
</mx:HTTPService>和使用<mx:WebService>标签时不同,你不需要定义操作。所有要发送到服务器进行处理的变量将作为键值对传到url属性定义的URL。这个标签的行为与HTML表单的get或post的行为相同。要向服务器传递数据,你只需要传递携带着那些变量的对象。Flex会将那些变量封装进正确的格式。下面的代码展示了对上面<mx:HTTPService>标记进行处理的ActionScript代码:public function httpServiceResult(e:ResultEvent):void {
Alert.show("received a result");
}
public function httpServiceFault(e:FaultEvent):void {
Alert.show("received a Fault");
}
public function sendHttpRequest():void {
var requestObj:Object = new Object();
requestObj.appid = new String("YahooDemo");
requestObj.query = new String("persimmon");
requestObj.results = new int(2);
yahooHTTPService. request = requestObj;
httpAsyncToken = yahooHTTPService.send();
}
使用HTTP Post和Get方法操作的WEB服务可以理解为REST服务。在很多情况下,使用HTTP Post方法。使用HTTP Web服务的一个明显的好处是你可以传递比使用SOAPWeb服务时更少的数据。
Adobe Flexx 数据访问组件使用远程过程调用(RPC)来与服务器环境交互,例如PHP,Adobe ColdFusion,和Microsoft ASP.NET,来为Flex程序提供数据,以及将数据传递给后台的数据源。 连接到一个HTTP Web服务可以很容易的使用<mx:HTTPSevice>。<mx:HTTPService>有着类似<mx:WebService>和<mx:HTTPService>标签的属性,且具有falt和result时间供你监听和处理,如下所示:
<mx:HTTPService id="yahooHTTPService"
url="http://search.yahooapis.com/WebSearchService/V1/webSearch"
method="GET"
makeObjectsBindable="true" result="httpServiceResult(event)"
fault="httpServiceFault(event)" showBusyCursor="true">
</mx:HTTPService>和使用<mx:WebService>标签时不同,你不需要定义操作。所有要发送到服务器进行处理的变量将作为键值对传到url属性定义的URL。这个标签的行为与HTML表单的get或post的行为相同。要向服务器传递数据,你只需要传递携带着那些变量的对象。Flex会将那些变量封装进正确的格式。下面的代码展示了对上面<mx:HTTPService>标记进行处理的ActionScript代码:public function httpServiceResult(e:ResultEvent):void {
Alert.show("received a result");
}
public function httpServiceFault(e:FaultEvent):void {
Alert.show("received a Fault");
}
public function sendHttpRequest():void {
var requestObj:Object = new Object();
requestObj.appid = new String("YahooDemo");
requestObj.query = new String("persimmon");
requestObj.results = new int(2);
yahooHTTPService. request = requestObj;
httpAsyncToken = yahooHTTPService.send();
}
转载于:https://blog.51cto.com/flexria/156699
总结
- 上一篇: SI9000常用共面阻抗模型的解释
- 下一篇: hisi3520dv400镜像烧录方法(