0

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(ResultEvent.RESULT,AdminUserList.saveUserPermListResult);
        ht.send();
    }
    public static function saveUserPermListResult(e:ResultEvent):void {
        trace(e);                   

    }
  1. How can I send the XMLList data to PHP? Should I add a toString() to it?
  2. 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.

Blue Sky
  • 807
  • 1
  • 15
  • 36
  • Hi Tomalak, didn't get you. Posted the screenshot of the sourcecode to show what I am trying. If there is a better way, please let me know. – Blue Sky May 25 '10 at 11:18

1 Answers1

0

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.

Community
  • 1
  • 1
Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Content type as "application/x-www-form-urlencoded" is not working. Just want to know how to send a xml string from Actionscript to PHP. The collection used in the code is XMLList. – Blue Sky May 26 '10 at 04:51
  • @Vish: Have you tried installing a network sniffer and looking at the packets that go over the wire? Maybe that's the first step to debug the problem. – Tomalak May 26 '10 at 07:41
  • Hi Tomalak, Thanks for the tips, actually tried another option. Split the XMLList to create a string and then sent the string to PHP. In the PHP, used the explode function to get the contents. Works fine. Thanks again. – Blue Sky May 26 '10 at 09:42