Quantcast
Viewing all articles
Browse latest Browse all 21156

Best solution for domain or url check

Hi

 

I just started using AIR and am developing a simple app to check the availability of a list of domains. There seems to be several options using the AIR api and I've been working on the code below.The core of it was taken from an example in the AIR docs.

 

All I need is to have the HTTP status code returned (200, 400, etc.).

 

URLMonitor looked like the way to go but I noted that on sites like Amazon it returned a 405 code instead of a 200. Other methods return a 200.

 

The problem I have with the code below is this: the  check_url_exists function calls the loader.load method and we wait for the httpStatusHandler to return the HTTPStatusEvent. Problem is the loop that's checking the url array continues to loop resulting in reversed and confused output. Obviously the functions called by the loader events are executing while the check_url_exists loop is executing.

 

So, is this the best solution for my needs, and if so, how can I get the loader event to finish before the next loop iteration proceeds?

 

Thanks in advance.

 

Note: I'm not using Flex.

 

-------------------------------------------------------------------------------------

var urls=[];
urls[0]="http://www.amazon.com";
urls[1]="http://www.google.com";
urls[2]="http://www.allmusic.com";
urls[3]="http://www.this_is_not_a_valid_domain.com";

 

var loader = new air.URLLoader();

 

configureListeners(loader);

 

function configureListeners(dispatcher) {
  dispatcher.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
  dispatcher.addEventListener(air.HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
  dispatcher.addEventListener(air.IOErrorEvent.IO_ERROR, ioErrorHandler);
  }
                       
function securityErrorHandler(event) {
    air.trace("securityErrorHandler: " + event);
        }

 

function httpStatusHandler(event) {
    air.trace("httpStatusCode: " + event.status + " - ");
        }

 

function ioErrorHandler(event) {
    air.trace("ioErrorHandler: " + event.errorID + " - ");
        }

 

for(var x=0;x<urls.length;x++){
  check_url_exists(urls[x],loader);
    }

 

function check_url_exists(url,loader) {

 

  var request = new air.URLRequest(url);
  request.authenticate=false;           
  request.method = air.URLRequestMethod.HEAD;
  loader.load(request);
  }


Viewing all articles
Browse latest Browse all 21156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>