4 Replies Latest reply on Oct 11, 2007 1:02 PM by furta

    posting an array parameter using HTTPService

    furta
      I am trying to post a set of xmls using the HTTPService. the code looks like this

      public function saveListDelegate( responder:IResponder, xml1:String, xml2:String){

      var variables :URLVariables;
      variables.xmlString = xml1;
      variables.xmlString = xml2;
      //trying to post http://localhost/app/data/xmlSaver.jsp?xmlString=<name id="1">...</name>&xmlString =<name id="2">...</name>
      var _service:HTTPService = ServiceLocator.getInstance().getHTTPService( "xmlSaver" );
      _service.requestTimeout = 3000;
      _service.method = "POST";
      _responder = responder;

      var call:AsyncToken = _service.send(variables);
      call.addResponder( _responder );
      }

      But this piece of code only posts one of the xmls and does not send the xmlString as a array of Strings.

      does anybody know how to do this...
        • 1. Re: posting an array parameter using HTTPService
          atta707 Level 2
          I think URLVariables class is meant to be used with URLRequest; from the docs:

          <quote>
          The URLVariables class allows you to transfer variables between an application and a server. Use URLVariables objects with methods of the URLLoader class, with the data property of the URLRequest class, and with flash.net package functions.
          </quote>

          as for the HTTPRequest based requests try this:

          var params:Object = new Object();
          o.p1 = "hello";
          o.p2 = "world";

          _service.send(o);

          HTH.

          ATTA
          • 2. Re: posting an array parameter using HTTPService
            furta Level 1
            "var params:Object = new Object();
            o.p1 = "hello";
            o.p2 = "world";"

            I have tried this too and it ends up with the same result. the only reference I could find anywhere on the web ( http://jessewarden.com/2007/06/page/2) says this.

            <Quote>
            HTTPService has 2 ways to give it stuff; either set it’s request property before sending or pass it in the send function. However, if a WebSevice accepts this:

            param=val1&param=foo&param=bar

            Well… you’re kind of screwed. There is only 1 param…

            var o = {};
            o.param = “uno”;
            o.param = “dos”; // overwrites uno
            o.param = “tres”; // overwrites dos… all are same param variable

            I tried my best to hack the IMessage object that’s associated with an HTTPService AsyncToken (mx.messaging.messages.HTTPServiceMessage I think), but no go. What to do? Uber l33t h@x of course!
            </Quote>

            I am looking for somebody to confirm my fears...

            Thanks for the reply...
            • 3. Re: posting an array parameter using HTTPService
              atta707 Level 2
              I'm using Flex Builder 3 Beta 2 and have a JEE application on the server side. Here is *working* code example from my project:

              var o:Object = new Object();
              var submodels:Array = new Array();

              submodels.push(this.CRE.id);
              submodels.push(this.LGC.id);
              submodels.push(this.MEM.id);
              submodels.push(this.RFS.id);
              submodels.push(this.AMS.id);

              o.submodels = submodels;

              this.xService.send(o);

              on the service side I get a an array of 'submode' request parameter.

              hope this helps.

              ATTA
              • 4. Re: posting an array parameter using HTTPService
                furta Level 1
                Thanks Atta.

                Already tried that.. In flex 2 the value on the server is a comma separated list of values.

                submodels.push("1");
                submodels.push("2");
                submodels.push("3");
                submodels.push("4");
                submodels.push("5");

                o.submodels = submodels;

                this.xService.send(o);

                in this case the server recieves a string called submodels as "1,2,3,4,5"

                Well that should explain most of it. I guess it was fixed for flex3...