檢測網頁地址有效性java代碼

來源:互聯網
上載者: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 從 HTTP 響應訊息擷取狀態代碼。 * 例如,就以下狀態行來說: HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized 將分別返回 200 * 和 401。 如果無法從響應中識別任何代碼(即響應不是有效 HTTP),則返回 -1。 *  * 返回 HTTP 狀態代碼或 -1 */int state = conn.getResponseCode();System.out.println(state);if (state == 200) {return true;} else {System.out.println("invalid: " + url_s);return false;}} catch (IOException e) {return false;}}}

  

檢測網頁地址有效性java代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.