views:

313

answers:

4

I apologize that there is a similar question already but I'd like to ask it more broadly.

Is there any way at all to determine on the client side of a web application if requesting a resource will return a 401 status code and cause the browser to display an ugly authentication dialog?

Or, is there any way at all to load an mp3 audio resource in flash which fails invisibly in the case of a 401 status code rather than letting the browser show an ugly dialog?

The Adobe Air run-time will suppress the authentication if I set the "authenticate" property of the URLRequest object but this property is not in the Flash run-time. Any solution which works on the client will do. An XMLHttpRequest is not likely to work as the resources in questions will be at different domains.

It is important to fail invisibly because the application will have a list of many audio resources to try and it makes no sense to bother the user to try and authenticate for one when there are many others available. It is important that the solution work on the client because the mp3's in question come from various servers outside my control.

+1  A: 

I'm having the same problem with the twitter api - any protected user requires the client to authenticate.

The only solution that I could come up with was to load the pages serverside and return a list of the urls with their http response code.

zaius
Twitter API has a `suppress_response_codes` parameter, which will force the response to have 200 OK status.
Jaka Jančar
A: 

"Is there any way at all to determine on the client side of a web application if requesting a resource will return a 401 status code and cause the browser to display an ugly authentication dialog?"

No, not in general. The 401 response is the only standard way for the server to indicate that authentication is necessary.

Jens Alfke
A: 

Just wrap your access to the resource that might potentially require authentication to an Ajax call. You can catch the response code, and use javascript to do whatever you want (ie. play that sound). If the response code is however alright, then use javascript to forward user to the resource.

Most likely this approach will generate slightly more load on server (you might have to resort to loading the same resource several times in some circumstances), but it should work. Any good tutorial about how to use XMLHttpRequest should contain all you need. Take a look at for instance http://www.xul.fr/en-xml-ajax.html

Ajax doesn't work across different domains, so that will only work if the page and the resource are on the same domain.
zaius
A: 

If you are using URLRequest to get the files, then you are running across more than just elegant error handling, you are running into a fundamental difference in the Flash and AIR run-times.

If using the URLRequest object to retrieve files you are going to get a security error from Flash on every request to every server that has not set a policy file to allow these sort of requests. AIR allows these requests since it basically IS the client. This makes sense since it's the difference between installing an application and visiting a web page.

I hate to provide the non-answer, but if you can't make a server-side call, and you are hitting a range of "not-known" servers, it's going to be a tough road to hoe.

But maybe I misunderstand, are you just trying to Link to the files and prevent the user from getting bad links, or are you trying to actually load the files?

zenWeasel
Thank you for your time regardless of whether or not I can get what I want.Yes, I am trying to load them and to play them. It is not important that any particular url work though, as I have many to try.
Joe Langeway