小智 11
它在Java中非常相似.您只需要评估HTTP响应代码:
final URL url = new URL("http://some.where/file.html");
url.openConnection().getResponseCode();
Run Code Online (Sandbox Code Playgroud)
可以在此处找到更完整的示例.
提供易于复制和粘贴的干净版本。
try {
final URL url = new URL("http://your/url");
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
int responseCode = huc.getResponseCode();
// Handle response code here...
} catch (UnknownHostException uhe) {
// Handle exceptions as necessary
} catch (FileNotFoundException fnfe) {
// Handle exceptions as necessary
} catch (Exception e) {
// Handle exceptions as necessary
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10272 次 |
| 最近记录: |