/ Published in: MXML
Quick example on how to do a POST request using Flex and the HTTPService class
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <!-- A. HTTPService is used to send the Message --> <mx:HTTPService id="sm" url="http://localhost:8081/sendmail" useProxy="false" method="POST" resultFormat="e4x"> <mx:request xmlns=""> <msgFrom> {msgFrom.text} </msgFrom> <msgTo> {msgTo.text} </msgTo> <msgSubject> {msgSubject.text} </msgSubject> <msgBody> {msgBody.text} </msgBody> </mx:request> </mx:HTTPService> <mx:Panel layout="horizontal" horizontalAlign="center" verticalAlign="middle"> <mx:VBox> <mx:Label text="Flex Client for Google App Engine" fontSize="15" fontWeight="bold"/> <!-- B. Form --> <mx:Form defaultButton="{sendMessage}" width="419"> <mx:Label text="Compose a Mail Message"/> <mx:FormItem label="From"> <mx:TextInput id="msgFrom" width="300" text=""/> </mx:FormItem> <mx:FormItem label="To"> <mx:TextInput id="msgTo" width="300" text=""/> </mx:FormItem> <mx:FormItem label="Subject"> <mx:TextInput id="msgSubject" width="300" text=""/> </mx:FormItem> <mx:FormItem label="Body"> <mx:TextArea id="msgBody" width="300" height="100" text=""/> </mx:FormItem> <mx:FormItem> <mx:Button id="sendMessage" label="Send" click="{sm.send()}"/> </mx:FormItem> </mx:Form> <!-- C. Previously Sent Messages Data Grid --> <mx:Label text="Previously Sent Messages"/> <!-- D. DataProvider is expecting to receive XML. It is BOUND to --> <mx:DataGrid id="dg" dataProvider="{sm.lastResult.message}"> <mx:columns> <mx:DataGridColumn headerText="From" dataField="from"/> <mx:DataGridColumn headerText="To" dataField="to"/> <mx:DataGridColumn headerText="Date" dataField="date"/> <mx:DataGridColumn headerText="Subject" dataField="subject"/> <mx:DataGridColumn headerText="Body" dataField="body"/> </mx:columns> </mx:DataGrid> </mx:VBox> </mx:Panel> </mx:Application>
URL: http://www.colettas.org/?p=240