首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA测试url是不是连通

2012-12-28 
JAVA测试url是否连通try{URL url new URL(url_s)HttpURLConnection conn (HttpURLConnection)url.ope

JAVA测试url是否连通

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{           return false;       }       }       catch(IOException e){           return false;       } 

热点排行