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"
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...
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:
<s:HTTPService id="xmlService" contentType="application/xml" method="POST" resultFormat="xml">
var xml:XML = new XML();
xmlService. url = "http://somelink.com";
xmlService.url = "http://somelink.com/file_name.asp?UserKey=" + userKey + "&UserId=" + userId;
Sorry I coulden't help, maybe some1 else knows more about.
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?
"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?"
"What version of AIR are you using?"
"Are you building a HTML or a 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.
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?
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.
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?
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.
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.
According to the documentation "Due to browser limitations, custom HTTP request headers are only supported for
POSTrequests, not for
Since you are trying a GET request, this does not work.