0

I have an air app and I want to add proxy-authorization header whenever my client is behind a proxy. I am adding 'proxy-Authoriztion' header in urlRequest headers but still I am getting the OS prompt for username/password.

var loader:HTMLLoader = new HTMLLoader();
var be:Base64Encoder = new Base64Encoder();
be.insertNewLines = false;
be.encode("test" + ":" + "test");    
var urlRequest:URLRequest = new URLRequest("http://google.co.in");
urlRequest.authenticate = false;
urlRequest.requestHeaders.push(new URLRequestHeader("Proxy-Authorization","Basic "+ be.toString())); 
page.htmlLoader.load(urlRequest);

I checked fiddler and what I see is that 1st Response is 301 and proxy-authorization header is added 2nd Response is 407 and proxy-authorization header is not added.

After this I get the OS prompt. Anybody has any ideas on this?

Mady
  • 5,016
  • 7
  • 35
  • 46

1 Answers1

0

I had that exact same problem, just for Authorization headers. Here is my solution:

var service:HTTPService = new HTTPService();
...
var encoder:Base64Encoder = new Base64Encoder();
encoder.encode(userName+':'+password);
service.headers["Authorization"] = "Basic " + encoder.toString();
...
service.send();

For some none apparent reason this works. Try that ( but remember to change the "Authorization" header in my example with "Proxy-Authorization")

NielsBjerg
  • 701
  • 4
  • 9
  • I am using urlRequest, cannot try with HTTPService. – Mady Aug 18 '11 at 08:37
  • To send a single request with Basic Authentication the approach you have mentioned is good but in case where you need to make many requests e.g. loading a web page that is password protected this approach won't work. you need to use URLRequestDefaults.setLoginCredentialsForHost() – Mady Aug 18 '11 at 09:24