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?