9 Replies Latest reply on Apr 11, 2008 6:55 AM by Bucko70

    HTTPService POST

    Bucko70 Level 1
      Hi all, HTTPService and method POST is confusing me a bit, trying to post some values to a webserver, when i use GET, its no problems, when using POST nothing is received at the server , and i cant se that values/data is posted with firefox and firebug.

      Snipplet:
      private function start():void
      {
      service = new HTTPService();
      service.url = " http://webserver.com";
      service.method = "POST";
      service.resultFormat = "object";

      var params:Object = new Object();
      params.ping= "pong";
      service.send(params);
      }

      Cant find any good explanation on this issue, am i doing something wrong?

      Thanx.
        • 1. Re: HTTPService POST
          slaingod Level 1
          Have you tried:
          service.request.ping = "pong";

          I've never used the send(params) method myself, always the other and never had an issue.
          • 2. HTTPService POST
            Bucko70 Level 1
            Hi, thank you for the response, tried your example, but the result is the same, no post of variable/value ping.
            I find this a little strange, POST & GET should work, any other solution?, i need to have the whole HTTPService in a method since i will be posting dynamic value/key pairs a lot.


            private function start():void
            {
            service = new HTTPService();
            service.url = " http://localhost:8080/test.aspx"
            service.method = "POST";
            service.resultFormat = "object";
            service.request.ping = "pong";
            service.send();
            }
            • 3. HTTPService POST
              SujitG Level 2
              Hi,
              The code you posted is perfectly fine. Please check out if you are you using the right methods for accessing the values on the server side, for example if you are using the java HTTPServlet, please make sure u are handling the doPost method for accessing the value sent using POST method. You can even try adding a fault event handler and see if there are any errors. Below is the code is used and i got the results on the server.

              private function start():void
              {
              var service:HTTPService = new HTTPService();
              service.url = " http://localhost:9191/helloworld/showresults.jsp";
              service.method = "POST";
              service.resultFormat = "object";
              service.addEventListener(ResultEvent.RESULT, resultHandler);
              var params:Object = new Object();
              params.ping= "pong";
              service.send(params);
              }

              Hope this helps.
              • 4. Re: HTTPService POST
                Mitek17 Level 1
                Try the following:

                service = new HTTPService();
                service.url = " http://webserver.com";
                service.method = "GET";
                service.resultFormat = "object";

                service.contentType = HTTPService.CONTENT_TYPE_FORM

                service send(Object({ping:"pong"}))


                I would think that you are getting a problem because HTTPService is confused with POST/GET methods and the contentType you sending. It defaults to the following : XML objects are sent via POST, unnamed Objects are sent via GET method. If you are not specifying them it could be confused.

                • 5. HTTPService POST
                  Bucko70 Level 1
                  Hi, thank you for the input.

                  It still wont do a post, if i use service.method = "GET"; and service.contentType = HTTPService.CONTENT_TYPE_FORM flex converts this query to a get, the result it parameters in the url xxx?ping=pong. This is not what im interested in, i want to make a standard POST with multiple variables?!, like a standard web form...

                  I tried SujitG example and that one dont work eather for me. On my server i have a simple way of listing the incoming values (both GET & POST), i get results on every try on GET, but none on POST.

                  aspx serverside:
                  foreach (string key in Request.QueryString.AllKeys)
                  {
                  Response.Write(String.Format("{0} = {1}<br/>", key, Request[key]));
                  }

                  foreach (string key in Request.Form.AllKeys)
                  {
                  Response.Write(String.Format("{0} = {1}<br/>", key, Request[key]));
                  }

                  jsp serverside:
                  out.print("request:"+ request.getParameter("ping"));

                  Any suggestions?

                  Thanx....
                  • 6. Re: HTTPService POST
                    Mitek17 Level 1
                    OK,
                    what happens if you do the following: (remove the resultFormat & set the faultHandler)

                    service = new HTTPService();
                    service.url = " http://webserver.com";
                    service.method = "POST";
                    service.contentType = HTTPService.CONTENT_TYPE_FORM;
                    service.requestTimeout = 10;
                    service.xaddEventListener("fault", fFaultHandler, false, 0, true);

                    service send(Object({ping:"pong"}))

                    ======================
                    private function fFaultHandler(event:FaultEvent):void
                    {
                    Alert.show(event.fault.message, event.fault.faultString);
                    }
                    • 7. Re: HTTPService POST
                      Bucko70 Level 1
                      Same problem, no POST of variables. This is driving me crazy ;-).
                      There must be some explanation on this issue.

                      Please use my test aspx page if you want to test yourself. http://flexlab.dnsalias.com/GetPost.aspx

                      code:
                      service = new HTTPService();
                      service.url = " http://flexlab.dnsalias.com/GetPost.aspx";
                      service.method = "POST";
                      service.contentType = HTTPService.CONTENT_TYPE_FORM;
                      service.requestTimeout = 10;
                      service.send(Object({ping:"pong"}));

                      • 8. Re: HTTPService POST
                        SujitG Level 2
                        Hi,

                        i tried this and its working. One thing i noticed is that for the first time i sent the request the request was timed out. But for the second time, i got the results. You can may be try increasing the time for the requestTimeout property.
                        Hope this helps.

                        Code i used:
                        private function sendData():void
                        {
                        var service:HTTPService = new HTTPService();
                        service.url = " http://flexlab.dnsalias.com/GetPost.aspx";
                        service.method = "POST";
                        service.addEventListener(ResultEvent.RESULT, resultHandler);
                        service.resultFormat = "text";
                        //service.requestTimeout = 10;
                        service.send(Object({ping:"pong"}));
                        }

                        private function resultHandler(event:ResultEvent):void
                        {
                        Alert.show(event.result.toString());
                        }

                        Response i got from the server:
                        • 9. Re: HTTPService POST
                          Bucko70 Level 1
                          Thanx for your test SujitG, now i got the same result as you. One thing was the requestTimeout.