7 Replies Latest reply on May 12, 2010 4:10 AM by Gupta.Himanshu

    HTTPService is not working.

    Gupta.Himanshu

      I  have an application in which I send an HTTP request using HttpService.send.

      It works fine when I run it using FlexBuilder but when I simply open the main.html file in web browser(directly) it stops working.

       

      In this case no Http Request is sent and the application is of no use.

       

      Can anyone tell me the reason. I tried searching but didn't get anything relevant.

        • 1. Re: HTTPService is not working.
          Sree_D Level 2

          What is the URL you are referring when launching from flex builder and the url you see in the browser address bar. Both should be same else you will get security sandbox violation if you are having a debugger version of flash runtime. Try using exactly same url in flex app and browser.

          • 2. Re: HTTPService is not working.
            Gupta.Himanshu Level 1

            I have declared the HTTPService as given

             

            <mx:HTTPService id="ipService" result="ipInfohandler(event)"/>

            and its URL is set on some parameters when some button is clicked.

             

            private function getIpInfo():void{

                        ipService.url="http://www.ipgp.net/api/xml/"+ipAddr.text;

                        ipService.send(null);

                        }

             

            "Try using exactly same url in flex app and browser."

            Are you talking abput the URL of the flash application file? In that case how can it be different. As if I deploy it somewhere then its URL is going to change.

            • 3. Re: HTTPService is not working.
              Sree_D Level 2

              Below is the situation I am trying to explain.Lets say testServ01 and 9080 is the server detail where your application containing main.html is deployed then you see the address as http://testServ01:9080/api/xml/ in browser address bar.

               

              Now in the mxml file which is sendig the request if the url is given like http://localhost:9080/api/xml then the swf file when embeddded in html will not work even if localhost and testServ01 are same.

               

              Flash runtime will not allow to access url that are different from the adress that is there in browser.

              1 person found this helpful
              • 4. Re: HTTPService is not working.
                Gupta.Himanshu Level 1

                Oh.. Thats was new to me. So is there any other way to achieve this?

                It makes no sense for me to make an application which can only send request from my local and not from any other machines/servers.

                • 5. Re: HTTPService is not working.
                  Sree_D Level 2

                       Use the below methods in mxml to get the url details dynamically.

                   

                   

                       /**
                       * Returns the current url that the swf player lives in
                       *
                       */
                       public static function getUrl():String
                       {
                        return ExternalInterface.call("window.location.href.toString");
                       }
                      
                       /**
                       * Returns the current host name.
                       * example: http://www.flexpasta.com/?x=1&y=2 would return www.flexpasta.com
                       */
                       public static function getHostName():String
                       {
                        return ExternalInterface.call("window.location.hostname.toString");
                       }
                      
                       /**
                       * Returns the current protocol, such as http:, https:, etc
                       *
                       */
                       public static function getProtocol():String
                       {
                        return ExternalInterface.call("window.location.protocol.toString");
                       }
                      
                       /**
                       * Gets the current port for the url
                       */
                       public static function getPort():String
                       {
                        return ExternalInterface.call("window.location.port.toString");
                       }
                      
                       /**
                       * Gets the context following the base of the url
                       * Example http://www.flexpasta.com/test?x=1&y=2 would return /test
                       */
                       public static function getContext():String
                       {
                        return ExternalInterface.call("window.location.pathname.toString");
                       }

                  • 6. Re: HTTPService is not working.
                    Gupta.Himanshu Level 1

                    Sree

                     

                    Thanks for your help.

                    I th ink I am not getting the point. What should I do with this information?

                    Ya I got the point that we can take full details of the URL.

                     

                    Please help if you have some time.

                    • 7. Re: HTTPService is not working.
                      Gupta.Himanshu Level 1

                      In my application I am loading data from cross domain and as i searched it needs an corss-domain policy file at the cross/data server.

                      But in this case the provider is third party and I dont have any control to their files/server.

                       

                      What can be done to solve this? Can we configure at the client/flex side that which domains are OK to get data?

                       

                      Himanshu Gupta