7 Replies Latest reply on Jan 5, 2007 3:14 AM by ojk007

    Sending Multiple Requests through mx:HTTPService

    deepakgsd
      Hi,

      I'm facing issues in sending multiple HTTP requests using the same HTTPService object. Please see my sample application below, it is a rather simple application with a panel and a single button. On button click, I submit a HTTP request to the server. The problem that I face is that the request gets submitted only the first time. Subsequent clicks of the button seem to have no effect and there seems to be no request made from the flash application. I monitoring the HTTP activity using a monitoring tool .
      Am I missing something here? Please advise.

      This is the mxml
      ------------------------------------------------------------------------------------------ ------------

      <?xml version = "1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:HTTPService id="srv"
      url = " http://localhost/MyWebSite/Default.aspx"
      showBusyCursor="true" method="GET" result="processResponse()" resultFormat="text"
      concurrency = "multiple">
      </mx:HTTPService>
      <!-- The processResponse() method does nothing more than print debug messages -->
      <mx:Script source = "SingleTestAS.as"/>

      <mx:Panel title="Hitting server more than once" height="90%" width="80%"
      paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
      <mx:ControlBar horizontalAlign="center">
      <mx:Button id="sb" label="Send Request" click="srv.send()"/>
      </mx:ControlBar>
      </mx:Panel>
      </mx:Application>

      ------------------------------------------------------------------------------------------ ------------

      This is the action script file SingleTestAS.as

      ------------------------------------------------------------------------------------------ ------------
      private function processResponse():void
      {
      trace("Start :Got Response");
      var response:Object = srv.lastResult;
      var responseString:String = response.toString();
      trace("Index is :" + responseString);
      trace("End :Got Response");

      }

      ------------------------------------------------------------------------------------------ ------------


      Regards,
      Deepak
        • 1. Re: Sending Multiple Requests through mx:HTTPService
          Level 1
          I'm going off on a limb here, because I'm not exactly sure how the flash engine works with the browser, but, it is possbile that your browser is caching the request/reply to the HTTPService, hence the reason it does not happen more than once? You should be able to turn the caching off in your browser to see if that is the case....

          You have your concurrency as multiple though, so the flex should be working as you thought.

          --Andy
          • 2. Re: Sending Multiple Requests through mx:HTTPService
            FlightGuy Level 1
            HTTPService Get request will be cached by your browser. There are two ways around this. One is the correct solution, and the other is the workaround.

            Workaround: Randomize your url by adding ?dummy=randomnumber. You can use the current time or anything else you want. This changes the url so the browser won't have a cached copy of it and will be forced to query the server again.

            Correct solution: Don't use GET - rather use POST. GET is intended to retrieve unchanging content from a web server. The browser assumes that another request for the same URL should produce the same result. POST, on the other hand, is intended for dynamic responses - the browser assumes that the returned document will be unique every time it is requested. Clearly you need to make sure your servlet responds to a POST method. I'm not a .NETter, so I can't tell you how to do that in your case, but I you don't already know I'm sure there's someone on this forum that will be able to tell you.
            • 3. Re: Sending Multiple Requests through mx:HTTPService
              ntsiii Level 3
              So THAT's why I have never had this problem myself! I have always used POST. I did not know that post prevented caching.

              Thanks,
              Tracy
              • 4. Re: Sending Multiple Requests through mx:HTTPService
                FlightGuy Level 1
                Yes - it's very tempting to use GET for everything because it's very easy to debug: just put the URL in your browser and there's the result. For a POST, it's not so simple to debug.

                I use a Tomcat server, and as a general rule I code my servlets to respond to both GET and POST - very simple to do, since you just override the service method (rather that doGet or doPost).

                That way I can debug and also do it properly.

                Tim

                PS. I'm honored to be able to teach you something new, Tracy

                • 5. Re: Sending Multiple Requests through mx:HTTPService
                  ntsiii Level 3
                  My backend technology of choice/comfort is .Net, specifically VB.NET, and in that I can access both get and post parameters very easily. So I started using post in Flex, but I can still debug using querystring urls, and I have never looked back.

                  I read your posts "religiously". You seriously know what you are talking about, and your explanations are superb. This is what "community" is all about.

                  BTW, have you discovered "flexcoders", a yahoo groups forum? If not, check it out.

                  Tracy
                  • 6. Re: Sending Multiple Requests through mx:HTTPService
                    Sir,
                    I think you can solve my problem, I am new to flex, in this I need to submit a query by using flex to server which runs at http://localhost:2020, from that server i need to get back the result into text area. This my prob.

                    Please tell me how can i do this by using httpservice in flex
                    • 7. Re: Sending Multiple Requests through mx:HTTPService
                      ojk007 Level 1
                      quote:

                      Originally posted by: nithya123
                      Sir,
                      I think you can solve my problem, I am new to flex, in this I need to submit a query by using flex to server which runs at http://localhost:2020, from that server i need to get back the result into text area. This my prob.

                      Please tell me how can i do this by using httpservice in flex


                      whats the query, whats your backend, whats the result your after?