2014-09-13 66 views

回答

4

您可以檢查響應代碼:

URL url = new URL("Your URL"); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
connection.connect(); 
int responseCode = connection.getResponseCode(); 

if (responseCode == HttpURLConnection.HTTP_OK) { 
// if Website is ok this wil be called 
} 
1

InetAddress包,有很多不同的方式來實現這一目標。

private boolean exists(String host){ 
    try{ 

    InetAddress.getByName(host); 
    return true; 
    }catch(UnknowHostException e){ 
    return false; 
    } 
}