0
可能重複:
Java HTTP getResponseCode returns 200 for non-existent URL檢測有效網址
你好,我的目標是在我下面的代碼但是構建一個決定HTML鏈接的有效性的應用程序,:
try
{
// create the HttpURLConnection
URL url = new URL("http://www.thisurldoesnotexist");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("Response code is " + connection.getResponseCode());
}
無意義的URL解析爲IP地址,我沒有想到,代碼retu該產品:「響應代碼是200」
看來我的方法來區分實際和不存在的頁面是有缺陷的。有誰知道我是否應用了錯誤的工具來確定網頁的有效性。 。 。即是否有更好的方式來區分現有和不存在的網頁。 。 。感謝這麼多,
你之前問過這個問題:[Java HTTP getResponseCode返回200爲不存在的URL](http://stackoverflow.com/questions/6211251/java-http-getresponsecode-returns-200-for-non-存在的URL)。檢查那裏的答案。 – dogbane 2011-06-02 08:15:09
請不要發表兩次相同的問題。 – 2011-06-02 08:16:56