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