Actionscript – confused about HttpService’s useProxy (Flex 3)

actionscriptactionscript-3apache-flexflex3mxml

I have a flex app, where the user can provide a link to a resource. I want to perform a simple validation and check if the url is actually valid (not just structure, but actually test the link to ensure I get a 200 OK).

I figured I would just use HttpService and use the HEAD method, but it seems that this is only available when you set useProxy to true, but I tried that and I still get errors; so I am pretty sure I am doing something wrong….here is a snippet of the code

var service:HTTPService = new HTTPService();
service.method = "HEAD"; 
service.url = url;
service.useProxy = true;
service.addEventListener(ResultEvent.RESULT, result);       
service.addEventListener(FaultEvent.FAULT, error);       
service.send();

Any idea what I am doing wrong? I am also open to other suggestions as to how to check if a url is valid (I would prefer to do this directly from Flex, without having to go back & forth to the server). Thanks.

EDIT (8/13/2009)

I implemented a simple UrlValidator by using a UrlLoader and assigning 2 listeners on it. one for IOError, and the other for Progress. My thinking was that Progress would act similar to a HEAD call, and I could just kill the stream after some amount of data was received. Unfortunately, the progress event is called in the case of a 404 or 403, which defeats the purpose. I also tried this with the Open event, but got the same results. Any ideas?

Best Answer

Adobe's Flex docs state: "When you do not go through the server-based proxy service, you can use only HTTP GET or POST methods. However, when you set the useProxy property to true and you use the server-based proxy service, you can also use the HTTP HEAD, OPTIONS, TRACE, and DELETE methods."

The server-based proxy service is referring to Live Cycle Data Services

I know AIR supports HEAD requests using the ServiceMonitor, but it looks like Flex on it's own doesn't.

Having a quick search around, it looks a few people have used sockets to roll their own custom URLLoader classes which can access the request headers - you could try one of them