I have url I want to check if it is live. I want to get bool value. How to do such thing?
相关问题
- UrlEncodeUnicode and browser navigation errors
- Improve converting string to readable urls
- Jasper: error opening input stream from url
- what's wrong in my URL validation Regex using
- Yii - Eliminate default controller ID for a module
相关文章
- C# HttpClient.SendAsync always returns 404 but URL
- Prevent $anchorScroll from modifying the url
- How does a browser handle cookie with no path and
- Base64URL decoding via JavaScript?
- Should I url encode a query string parameter that&
- MVC3 URL parameters - avoiding malicious attacks/s
- Call external URL from android and get response
- Regex to validate the index of a website vs. a spe
You can use an URLLoader and listen for the events to check if it loads, and if not what might be the problem. Would be handy to use the AIRMonitor first to make sure the client's computer is online in the first place.
Here is a class I started to write to illustrate the idea:
and here's a basic usage example:
The idea is simple: 1. You create a checked 2. Listen for the COMPLETE event(triggered when it has a result 3. In the handler check if it's live and what it logged.
In the HTTP specs, 200 area seems ok, but depending on what you load, you might need to adjust the class. Also you need to handle security/cross domain issue better, but at least it's a start.
HTH
An important consideration that George's answer left out is the URLRequestMethod. If one were trying to verify the existence of rather large files (e.g, media files) and not just a webpage, you'd want to make sure to set the method property on the
URLRequest
to URLRequestMethod.HEAD.As stated in the HTTP1.1 Protocol:
Hence, if you really only want to verify the existence of the URL, this is the way to go.
For those who need the code spelled out:
Otherwise, George's answer is a good reference point.
NB: This particular
URLRequestMethod
is only available in AIR.