** Use a Java program to determine the validity of a link

Source: Internet
Author: User
  1. Try{
  2. URL url =NewURL (url_s );
  3. Httpurlconnection conn = (httpurlconnection) URL. openconnection ();
  4. /**
  5. * Public int getresponsecode () throws ioexception
  6. * Get the status code from the HTTP Response Message.
  7. * For example, for the following status lines:
  8. * HTTP/1.0 200 OK
  9. * HTTP/1.0 401 unauthorized
  10. * 200 and 401 are returned respectively.
  11. * If you cannot identify any code from the response (that is, the response is not a valid HTTP),-1 is returned.
  12. *
  13. * Http status code or-1 is returned.
  14. */
  15. IntState = conn. getresponsecode ();
  16. System. Out. println (State );
  17. If(State = 200 ){
  18. Return True;
  19. }
  20. Else{
  21. Return False;
  22. }
  23. }
  24. Catch(Ioexception e ){
  25. Return False;
  26. }

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.