1 Reply Latest reply on May 27, 2007 6:26 PM by BLXWebMaster

    how to hadle HTTPService result?

    aq2sllik
      Hi I use the HTTPService class to send a request and I have a result in an XML format.... I've specified that I want the result format to be an array...

      so now how do I handle the result object as an Array and get the data?

      here is some code...

      public function post(method:String, param:Array):void
      {
      var http:HTTPService = new HTTPService();
      http.url = this.server;
      http.contentType = HTTPService.CONTENT_TYPE_FORM;
      http.resultFormat = HTTPService.RESULT_FORMAT_ARRAY;
      //http.makeObjectsBindable = true;
      http.method = "POST";

      //add extra params
      param['api_key'] = this.apiKey;
      param['method'] = method;
      param['sig'] = createPostSig(param);

      http.addEventListener(FaultEvent.FAULT, postFault);
      http.addEventListener(ResultEvent.RESULT, postResult);

      http.send(param);

      }

      private function postResult(e:ResultEvent):void
      {
      //HOW DO I GET THE DATA IN THE ARRAY FORMAT???
      }


      thanks
        • 1. Re: how to hadle HTTPService result?
          BLXWebMaster
          This is a sample of what I would do. Sample of a simple customer xml file retrived from a post to a PHP page. Make sure to review the format of your XML and modify the event result handler.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application
          xmlns:mx=" http://www.adobe.com/2006/mxml"
          layout="absolute"
          creationComplete="customersRPC.send();">

          <mx:Script>
          <![CDATA[
          import mx.collections.*;
          import mx.controls.*;
          import mx.rpc.events.*;
          import mx.events.*;

          [Bindable]
          private var customers:ArrayCollection = null;
          private function customersRPCResult(event:ResultEvent):void {
          customers = new ArrayCollection();
          customers = event.result.customers.person as ArrayCollection;
          }

          // Fault handler - displays the error
          private function customersRPCFaultHandler(event:FaultEvent):void
          {
          Alert.show(event.fault.message, "Could not load customers XML");
          }
          ]]>
          </mx:Script>

          <mx:HTTPService
          id="customersRPC"
          showBusyCursor="true"
          url=" http://127.0.0.1/Test1/bin/customers.php"
          result="customersRPCResult(event);"
          method="POST";
          fault="customersRPCFaultHandler(event);">
          <mx:request>
          <api_key>this.apiKey</api_key>
          <method>method</method>
          <sig>createPostSig(param)</sig>
          </mx:request>
          </mx:HTTPService>


          <mx:Panel x="63" y="129" width="493" height="200" layout="absolute" title="Customer Search" id="panel3">
          <mx:DataGrid x="10" y="36" width="453" id="customerInfo" height="114" dataProvider="{customers}" >
          <mx:columns>
          <mx:DataGridColumn headerText="Last Name" dataField="last"/>
          <mx:DataGridColumn headerText="First Name" dataField="first"/>
          <mx:DataGridColumn headerText="Phone Number" dataField="home"/>
          </mx:columns>
          </mx:DataGrid>
          </mx:Panel>
          </mx:Application>