flex Httpservice 访问php 参数为null
看cookbook到了数据访问。开始便给出了Httpservice示例,我按着书中所说布置了工程,把代码copy到工程里:
这是flex的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:HTTPService url="http://localhost:18000/index.php"
id="service"
result="serviceResult(event)" fault="serviceFault(event)"
method="GET" contentType="application/xml"
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;
import mx.controls.Alert;
[Bindable]
private var requestedId: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 {
try{
requestedId = input.text;
service.send();
}catch(e:Error){
Alert.show(e.message);
}
}
]]>
</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>
<?php
$id = $_GET["id"];
echo('<id>'.$id.'</id><name>ok</name><age>30</age>');
?>