2 Replies Latest reply on Jan 17, 2009 6:41 PM by ntsiii

    POST and HTTPService question...

    JoelSisko
      Newbie at developing and I am trying to build a simple form that will POST using HTTPSerivce. When I use the code below, the underscores are encoded and sent as "&5F" and the existing PHP on the server does not work with it , how do I prevent this from happening?

      #############Begin Code###################

      <mx:HTTPService resultFormat="text" result="userResult(event)" id="httpAdduser"
      url=" http://localhost/admin/index.php?sec=user" showBusyCursor="true" useProxy="false"
      method="POST">
      <mx:request xmlns="">
      <admin_action>add</admin_action>
      <place_next>2</place_next>
      </mx:request>
      </mx:HTTPService>

      #############End Code###################

        • 1. Re: POST and HTTPService question...
          ntsiii Level 3
          Build the request object in Actionscript code instead of in declarative mxml. I think that will leave your parameter names alone:

          private function getData():void [
          var oRequest:Object = new Object();
          oRequest.admin_action= "add";
          oRequest.place_next= "2";
          var callToken:AsyncToken = httpAdduser.send(oRequest);
          • 2. Re: POST and HTTPService question...
            ntsiii Level 3
            Also I advise setting resultFormat="e4x" on the HTTPService tag.

            Otherwise, Flex will convert your result xml into a tree of dynamic objects. This is rarely desirable. "e4x" is the current Actionscript implementation of XML.

            I see you are using a result hanlder. This is good, make it a habit, and avoid binding directly to lastResult. with an e4x result format, in you handler do something like:
            var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
            trace(xmlResult.toXMLString()); to verify that you have the result xml you expect

            You also need a fault handler.