我试图通过我的程序验证网址是否存在。该网站确实存在,但此方法不断抛出IO异常。
try{
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(webAddress).openConnection();
con.setRequestMethod("HEAD");
if (con.getResponseCode() == HttpURLConnection.HTTP_OK)
return "good";
else
return "bad";
}
catch (Exception e){
e.printStackTrace();
return "IOException thrown";
}
事件虽然我知道地址存在但我使用这个网站仔细检查了响应代码:http://tools.seobook.com/server-header-checker/,它正在响应200 OK
感谢您的帮助
12-13 14:31:48.619 13123-13123/com.mmappz.catacase W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-13 14:31:48.619 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
12-13 14:31:48.619 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
12-13 14:31:48.619 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
12-13 14:31:48.619 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
12-13 14:31:48.629 13123-13123/com.mmappz.catacase W/System.err﹕ at com.mmappz.catacase.StartScreen.checkCode(StartScreen.java:130)