5 Replies Latest reply on Mar 16, 2007 5:29 PM by ntsiii

    Using HTTPService with parameters

    Tom L Level 1
      Does anyone have any sample code that shows how to pass multiple parameters via HTTPService using the GET method. I have plenty of php pages I can reuse that receive data via the GET method. I have been unable to find working examples of how to use the httpservice and pass multiple parameters to a php page, which returns xm.

      Thanks,
      Tom
        • 1. Re: Using HTTPService with parameters
          JeffreyGong
          Hi Tom,

          You may try the code as follows,

          Jeffrey

          ------------------------------------------------------------------------------------------ -----------------
          <mx:Script>
          <![CDATA[
          private function init():void {
          var requestObj:Object = new Object()
          requestObj.param1 = "param1"
          requestObj.param2 = 34.76
          requestObj.param3 = 0
          requestObj.param4 = "param4"
          srv.request=requestObj
          srv.send()
          }

          private function onResult(event:ResultEvent):void {
          out.text = "event.result = " + event.result
          }
          ]]>
          </mx:Script>

          <mx:HTTPService id="srv" url=" http://webserver/path/to/some.jsp" result="onResult(event)" method="GET"/>

          <!-- mx:HTTPService id="srv" url=" http://webserver/path/to/some.jsp" result="onResult(event)" method="GET">
          <mx:request>
          <param1>param1</param1>
          <param2>34.76</param2>
          <param3>0</param3>
          <param4>param4</param4>
          </mx:request>
          </mx:HTTPService -->

          <mx:TextArea id="out" width="400" height="300"/>

          ------------------------------------------------------------------------------------------ -----------------------------
          • 2. Re: Using HTTPService with parameters
            ntsiii Level 3
            Jeffrey did not stati it clearly so I will.

            Those two approaches are functionally equivalent.

            I very much prefer the first because you can easily use variables to populate the request object. You cando that also in the declaritive form, using binding.

            Also, be aware that "get" calls often cache the data, and have a limit to the amount og data you can send. "post" does not suffer from these failings.

            Tracy
            • 3. Re: Using HTTPService with parameters
              phi2265 Level 1
              POST calls are cached as well. I had this problem with my XML docs. My solution was to append a random number to the end of them.


              • 4. Re: Using HTTPService with parameters
                Tom L Level 1
                Jeffery,
                thanks for taking the time to respond. I do have one question? In the following code: You repeated the HTTPService and inside it, the mx:request, but isn't the <!-- a comment, so isn't the mx:request part of the comment?
                Thanks,
                Tom
                <!-- mx:HTTPService id="srv" url=" http://webserver/path/to/some.jsp" result="onResult(event)" method="GET">
                <mx:request>
                <param1>param1</param1>
                <param2>34.76</param2>
                <param3>0</param3>
                <param4>param4</param4>
                </mx:request>
                </mx:HTTPService -->
                • 5. Re: Using HTTPService with parameters
                  ntsiii Level 3
                  "POST calls are cached as well"
                  I cannot refute this, but heard otherwise. I use post exclusively, but never directly access xml files, always going through a server-side proxy.

                  Tracy