Use HTTPService. Don't mess with contentType, but send your xml as a
string in a name=value pair. Set the method as post. Set
resultFormat="e4x". It will work without any problems,
Tracy
Sample code using HTTPService, e4x, handler function to populate a list
item.
Also shows usage of AsyncToken.
The DataGrid tag:
<mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>
The HTTPService tag:
<mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)"
fault="..../>
Script block declaration:
import mx.rpc.Events.ResultEvent;
[Bindable]private var _xlcMyListData:XMLListCollection;
Invoke send:
var oRequest:Object = new Object();
oRequest.Arg1 = "value1";
var callToken:AsyncToken = service.send(oRequest);
token.callId = "myQuery1";
Result Handler function:
private function onResult(oEvent:ResultEvent):void {
var xmlResult:XML = XML(event.result); //converts
result Object to XML. can also use "as" operator
var xlMyListData:XMLList = xmlResult.myListData; //depends on xml
format, is row data
_xlcMyListData = new XMLListCollection(xlMyListData); //wrap the
XMLList in a collection
trace(_xlcMyListData.toXMLString()); //so you can see
exactly how to specify dataField or build labelFunction
var callToken:AsyncToken = oEvent.token;
var sCallId = callToken.callId; //"myQuery1"
switch(sCallId) { //Process the
result conditionally
case "myQuery1":
doQuery2(); //do whatever
break;
...
}
}//onResult
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of i.yoho
Sent: Sunday, October 28, 2007 2:16 PM
To: [email protected]
Subject: [flexcoders] POST vs GET vs SEND ...not the same inside Flex
The more I play with this, the more I am convinced that it is acting
wrong because of Flex. I am watching the Apache server access.log as
the data goes by. And I just can't figure this out. My apologies for
the cross-post with Flash-Tiger group but I haven't heard anything and
thought it might be more appropriate here if Flex is causing the error.
I am working from the example in the Actionscript 3 cookbook chapter
20.13 trying to learn how to properly send XML data to a server-side
script. I have tried this a couple ways but haven't been able to get
past xml parsing errors with the basic HTTPService send. And to
compound matters, I am trying to learn Flex at the same time.
This code is from chapter 20.13 but to get any data to pass I have to
switch it from a .POST to a .GET. From what I have read, the .POST is
the right way. Has anybody been through this? Any advice greatly
appreciated.
var request:URLRequest = new URLRequest( "/saveResults.php" );
// Set the data property to the dataToSave XML instance to send
the XML
// data to the server
request.data= dataToSave;
// Set the contentType to signal XML data being sent
request.contentType = "text/xml";
// Use the post method to send the data
request.method = URLRequestMethod.POST;
// Create a URLLoader to handle sending and loading of the XML data
var loader:URLLoader = new URLLoader( );
// When the server response is finished downloading, invoke
handleResponse
loader.addEventListener( Event.COMPLETE, handleResponse );
// Finally, send off the XML data to the URL
loader.load( request );
}
Thanks,
Imogene