Detecting Web page address validity Java code

Source: Internet
Author: User
Package Com.inspur.linkcheck;import Java.io.ioexception;import Java.net.httpurlconnection;import Java.net.URL; public class Linkcheck {public static void main (string[] args) {System.out.println (Checkurl ("HTTP/ 202.110.193.23:8000/zrqd/themes/default/skins/images/bg_body_footer.png "));} public static Boolean Checkurl (String url_s) {try {URL url = new URL (url_s); HttpURLConnection conn = (httpurlconnection) url.openconnection ();/** * public int Getresponsecode () throws IOException from The HTTP response message gets the status code. * For example, for the following status lines: http/1.0-OK http/1.0 401 Unauthorized will return 200 * and 401 respectively. Returns 1 if no code is recognized from the response (that is, the response is not a valid HTTP). *  * Returns the HTTP status code or-1 */int state = Conn.getresponsecode (); System.out.println (state), if (state = =) {return true;} else {System.out.println ("Invalid:" + url_s); return false;}} catch (IOException e) {return false;}}}

  

Detecting Web page address validity Java code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.