Flex HTTPService and PHP

Posted by druva | Flex, as3 | Monday 13 October 2008 1:29 am

This examples shows how to use HTTPService for communicating with php.


 <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="fnCreationComplete()">
<mx:HTTPService id="httpserv"
url="http://localhost/test/httpserv.php"
result="diplayResult(event)"
fault="handleFault(event)"
method="POST"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function fnCreationComplete():void {
var Obj:URLVariables=new URLVariables();
Obj.username=2;
Obj.pass=5;
httpserv.send(Obj);
}
private function handleFault(event:FaultEvent):void{
Alert.show("faultString="+event.fault.faultString, "Error ID="+event.fault.errorID);
}

private function diplayResult(event:ResultEvent):void{
Alert.show(event.result.toString());
}
]]>
</mx:Script>
</mx:Application>

here is the Php code–


 echo 'User name is '.($_POST['username'].' and password is '.$_POST['pass']);