Send xml from ActionScript to PHP
I have values inside an XMLList in Actionscript. Need to send these values to the DB and update it. My actionscript code is as follows:
public static function saveUserPermList():void {
var ht:HTTPService = new HTTPService();
ht.url = Config.getServerURL();
ht.method = URLRequestMethod.POST;
//ht.resultFormat = "e4x";
ht.contentType = "text/xml";
ht.request["action"] = "saveUserPermListXML";
ht.request["pdata"] = Application.application.userPermListModel.toString();
ht.addEventListener(Re开发者_如何学运维sultEvent.RESULT,AdminUserList.saveUserPermListResult);
ht.send();
}
public static function saveUserPermListResult(e:ResultEvent):void {
trace(e);
}
- How can I send the XMLList data to PHP? Should I add a toString() to it?
- Also what should be the contentType in Flex.
How can I catch this inside PHP, pl let me know, trying to use, this way,
if($user -> isAllowedAccess()) {
header("Content-type:text/xml");
$postedData = $_POST["pdata"];
// $xmldoc = simplexml_load_string($POST['pdata']);
// echo($xmldoc);
}
No luck. Pl let me know.
The method
property of HTTPService
should probably be "POST", and the contentType
for the request itself should probably be "application/x-www-form-urlencoded".
On the PHP side, $_POST["pdata"]
would then be a string containing XML markup. You could either save that in a database directly, or first parse it into XML (via SimpleXML
or DOMDocument
) and do something with the contained data.
PS: I've just found this answer that seems to shed some light on the internal behavior of the HTTPService
class.
精彩评论