4 Replies Latest reply on Aug 23, 2007 11:03 AM by brado77

    HTTPService URLs

      I have a Flex app I have created which invokes HTTPService requests to get server-side data....pretty standard. In order to invoke an HTTPService request, of course, you need the URL of the host you are trying to hit. This URL is effectively different depending on where I deploy my web application, i.e., when I deploy my app to server X, I want the Flex app accessed there to be invoking its HTTPService requests against server X, and when I deploy my app to server Y, I want the Flex app accessed there to be invoking its HTTPService requests against server Y -- but I don't want to have to change code to do this. In other words, I want the flex app to know the host it came from, and invoke requests against that host.

      What I am looking for is the proper (standard) way to get that URL of the host. The mx.core.Application object has a url property, which I think under most circumstances could be parsed and work, but this creates a problem when running my Flex app in the Flex Builder debugger, as it gives me a file system path as the URL.

      What is the generally accepted standard way to bind the Flex app to the appropriate server it is supposed to direct server requests to without hard-coding this in Actionscript code?


        • 1. Re: HTTPService URLs
          JKohn99 Level 1
          I'm not sure there is a standard way, we use an approach similar to yours where
          we parse the url where we were served from. For launching from
          Flex builder we just added a bit of logic to use an standard url if we get the file path.

          We also externalize other urls we need in a xml file that we deploy to the web server. So we parse the url that the app was served from. Fetch the xml file and use those url's for other processing.

          Also you can always deploy to your local web server and still debug. That is what I do so I always see any sandbox errors. You just need to change the launch config to point to a server url instead of the ffile url
          • 2. Re: HTTPService URLs
            ntsiii Level 3
            One approach I have used is to specify the url in the HTML wrapper file and pass it in as a flashvar.
            • 3. Re: HTTPService URLs
              ntsiii Level 3
              This is avoids the Flex Builder problem.
              • 4. Re: HTTPService URLs
                brado77 Level 1
                Thanks for the replies, gents! I'll give these approaches a shot. Tracy, one note -- since my deployment artifact is actually a WAR file (Java webapp), inside of which both the flash swf and the html file sits, using a flash var is essentially the same situation I'm experiencing now -- rather than having to change Actionscript code to accommodate deploying to a different host, I'd have to change the Flash var value. Different file, but still a code change.

                Ideally, I was hoping that there would be some standard application property exposed which would produce the host + application root which could then be used by all HTTP requests -- seems logical, a flash app making requests is typically going to be requesting from the host it came from. Parsing the Application URL is pretty close, so I'll probably go that route.

                Thanks again for the responses.