5 Replies Latest reply on Aug 23, 2009 7:03 AM by Augusto Esteves

    Help: Sending HTTPService request using POST to a php script

    sugu0925

      Hello all,

       

      I need help in learning the proper method of communicating to php scripts from flex 3. I am very new to flex 3, php and web development. Thanks!

       

      What I am trying to do is as follows:

      1. User drags and drops a few items in a list control

      2. user clicks a button to send these keywords to server php script

      3. server will form a query based on the words sent and retrieve records and send them back

       

      Here is what I have done so far:

      1. When I send a request to server without any parameters, I amable to receive the request and query the database and send results in xml format

       

      current issues I am facing:

      1. I am gathering the list of entries in list control as follows:

      <*** this function is callled when user decides to send request to server ***>

      private function startsearch():void {
         var i:int;
         var myAC:ArrayCollection = ArrayCollection(SelCtypes_id.dataProvider);
         var nct:XML = new XML("<contenttypes></contenttypes>");
        
         // add contenttype child now
         for (i = 0; i<myAC.length; i++) {
          nct.appendChild(XML(<contenttype>{myAC[i].toString()}</contenttype>));
         }
         var params:Object = new Object();
         params.contenttypes = nct.toXMLString();
         getsearchresults.send(params);
        }

       

      <*** my http service entry****>

        <mx:HTTPService id="getsearchresults"
         method="post"
        url="http://localhost/search_xml.php"
        result="handlesearchresultsXml(event)"
        contentType="application/xml" />
       

      This is what I see in flex debugger just when the request is sent out:

      -> just before gersearchresults.send(params) call:

      params.contenttypes = "<contenttypes>
        <contenttype>AVI</contenttype>
        <contenttype>SWF</contenttype>
      </contenttypes>"

       

      <*** within the HTTPrequest send function, I see th following in debugger ***>

      message.contentType="application/xml"

      message.body = paramsToSend shows "

      <contenttypes>&lt;contenttypes&gt;

      &lt;contenttype&gt;AVI&lt;/contenttype&gt;

      &lt;contenttype&gt;SWF&lt;/contenttype&gt;

      &lt;/contenttypes&gt;</contenttypes>"

       

      This looks like my XML object is again formatted by an out <contenttypes> tag and the string is converted to be HTML safe (i.e. &lt, &gt notation).

       

      It looks like I am not doing something right with my params formation to XML and HTTPservice is reformatting it to be some form of XML (I do not know XML well either :-)

       

      My questions:

       

      1. What am I doing wrong?

      2. If there is a good example where I can send multiple parameters from flex client to php server and get data back where the request parameters will beof the form...

      <query>

      <type1>

           <type1val>value1</type1val>

           <type1val>value2</type1val>

      </type1>

      <type2>

           <type2val>value3</type2val>

           <type2val>value4</type2val>

           ...

      </type2>

      </query>

       

      Thanks for your help!