11 Replies Latest reply on Sep 24, 2010 8:42 AM by reflexactions

    I need help on this

    reflexactions Level 1

      I have been stuck with an AIR app for several months running round in circles trying to solve a basic problem and I really don't know where to go from here short of abandoning it.

       

      All I need to do from the AIR application is open a particular URL in a browser window setting a header or a cookie on the get request.

       

      Thats it, nothing more, I have dumbed everything down so that this is all I need.

       

      I have tried asking this question on these forums before in one way or another and I can't get any answer at all.

       

      Any suggestion welcome.

        • 1. Re: I need help on this
          blacksyforce Level 1

          I don't understand the "set a header or cookie on the get request"... you want to make a GET request ? or you want to send something in the request ?

           

          Anyway for the "open an URL in a browser window" is something like this:

           

          var urlRequest:URLRequest = new URLRequest(url); // url = "http://google.com";
          navigateToURL(urlRequest, type)); // type = "_blank" or "_top" or "My Page"

          • 2. Re: I need help on this
            reflexactions Level 1

            Cant really think of another way to say it but 'GET' request always contain headers when they are sent to the server.

            I want to make a 'GET' request (URLRequest) and I want set a header (URLRequestHeader) on that request (URLRequest) object so that the header gets sent to the server.

             

            So per your code:

            //CREATE THE URLReuqest

            var urlRequest:URLRequest = new URLRequest(url); // url = "http://google.com";
            //NOW SET A URLRequestHeader
            request.requestHeaders.push(new URLRequestHeader("Custom1", "UserKey="+UserKey+"; "+"UserID="+UserID));
            //THEN MAKE THE CALL AND THE HEADER SHOULD BE SENT WITH THE REQUEST
            navigateToURL(urlRequest, type)); // type = "_blank" or "_top" or "My Page"

             

             

            Thats what I want to do....

             

            So how do I do it...

            • 3. Re: I need help on this
              blacksyforce Level 1

              Now I understand, but I'm not very good at networking, I only made one project and I used the HTTPService and I was sending an XML with the POST method or edited the URL for the GET method:

               

              HTTPService

               

              <s:HTTPService id="xmlService" contentType="application/xml" method="POST" resultFormat="xml">

              <s:request xmlns="">

              </s:request>

              </s:HTTPService>

               

              POST

               

              var xml:XML = new XML();

              xmlService. url = "http://somelink.com";

              xmlService.send(xml);

               

              GET

               

              xmlService.url = "http://somelink.com/file_name.asp?UserKey=" + userKey + "&UserId=" + userId;

              xmlService.send();

               

              Sorry I coulden't help, maybe some1 else knows more about.

              Cheers ^^,

              • 4. Re: I need help on this
                mihnea1975 Adobe Employee

                Hi,

                 

                Let's see if i understood your problem. You are trying to:

                 

                1. Open a link in a browser window.

                2. The GET request you are sending must contain a custom header that you are programmatically setting before firing the request.

                 

                From your description, It is not clear whether the problem is that you do not see the custom header in the http packet or other problem. How did you try to inspect the HTTP packet that your application is sending? What type of OS are you using? What version of AIR are you using? Are you building a HTML or a Flex app?

                 

                Regards,

                Mihnea Ovidenie

                AIR Engineering

                • 5. Re: I need help on this
                  reflexactions Level 1

                  Hi,

                   

                  "How did you try to inspect the HTTP packet that your application is sending?"

                  1) Using 'Charles'.

                  2) Also on the server I echo back all the headers in to the requested page as a test.

                   

                  "What type of OS are you using?"

                  Windows Vista

                   

                  "What version of AIR are you using?"

                  AIR 2

                   

                  "Are you building a HTML or a Flex app?"

                  Flex App

                   

                   

                  Though I don't think it so important to understand my problem only what I want to do - I really would be happy for anyone to post any code for a flex app, on any version of air, on any os, that actually works.

                  • 6. Re: I need help on this
                    mihnea1975 Adobe Employee

                    Hi again,

                     

                    When calling the *navigateToUrl* method you are actually telling AIR to use the default browser on that machine to perform the HTTP request. You can specify the URL and the post data to the browser instance but not a custom http header. When the request is made by AIR runtime as opposed to the browser - when using HTMLLoader object for instance with the URLRequest object - you can specify a custom http header (but I assume you already know this).

                     

                    That being said, can you describe what you are trying to achieve? Maybe there is another way to solve it?

                     

                    Regards,

                    Mihnea Ovidenie

                    AIR Engineering

                    • 7. Re: I need help on this
                      reflexactions Level 1

                      Ok so no custom header and therefore no cookies either I assume as they are sent as a header right?

                       

                      What I am trying to achieve ...  something very simple ... the web page to be opened requires a 'key' to be passed in for security reasons.

                       

                      That key is known to the AIR app already, as it has logged in to the server and obtained a key previously.

                       

                      That key is normally set as session cookie in the web version of the Flex app, but it can equally be set as a custom header.

                       

                      Of course in the real app the web page being returned contains hundreds of links and they too can be clicked on to load another page which has hundreds more links etc. etc. and every time the requested page requires either a cookie or a custom header to be sent with the request with the key set.

                       

                      The key cannot be passed on the actual url string.

                       

                      This is a very large commercial app that we have been using under Flex for years, but this looks like it is impossible to run it under AIR.

                      • 8. Re: I need help on this
                        mihnea1975 Adobe Employee

                        Hi again,

                         

                        I want to clarify something: are you saying that navigateToUrl used to work in a Flex application? Have you been able in the past to set up a custom header/cookie before opening the page in the Web browser from a Flex application?

                         

                        Have you considered opening the url from within HTMLLoader?

                         

                        Regards,

                        Mihnea Ovidenie

                        AIR Engineering

                        • 9. Re: I need help on this
                          reflexactions Level 1

                          Yes, because when flex runs in a web page you can use the external interface to set the key in a session cookie as a one time action just after login and then throughout the life of the application any navigateToUrl call will automatically send that cookie to the server as part of the request. Basically that method allows you to set any cookie on any call if you really want to.

                           

                          That works perfectly... but it's not AIR obviously.

                           

                          With AIR if as you say you cannot add a header or a cookie to URLRequest object that you pass to the navigateToUrl function then there is no way to do that as every request appears to be a new session.

                           

                          Have we considered using HTMLLoader, yes which is why we are here;

                          Ultimately the HTMLLoader route will fail at some point, we had to do a lot of overriding classes, but at the end of the day we couldn’t get it to work in all cases, here what I am particularly talking about it that we going many layers down, i.e first layer is fine use the loader to load a page, then that page has links on it that are clicked, we need to intercept those requests and once again add the cookie/header, then when that returns a page it has links on it and when clicked those calls need to be intercepted.... ad infinitum.

                          Now we then found that was further complicated because some links need to open in a new window and other just navigate in the current window, some were javascript executed calls to open a new window and then go to a url, others were just href's on 'A' tags.

                          We were unable to get working some code that could handle all such cases.

                           

                          All this complexity is handled transparently by the browser so we therefore fell back to the idea that we would just open the first request in a browser window and we could then forget about everything else but as we then find there was no way to set a security key and therefore the user gets face with a login screen in the html page.

                          • 10. Re: I need help on this
                            mihnea1975 Adobe Employee

                            Hi,

                             

                            According to the documentation "Due to browser limitations, custom HTTP request headers are only supported for POST requests, not for GET requests."

                            http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.ht ml?allClasses=1#requestHeaders.

                             

                            Since you are trying a GET request, this does not work.

                             

                            Regards,

                            Mihnea Ovidenie

                            AIR Engineering

                            • 11. Re: I need help on this
                              reflexactions Level 1

                              And cookies?