且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查java是否存在网页?

更新时间:2023-11-27 18:48:46

即使你可以搜索你的答案:
一种简单的方法是使用 Apache Http组件

Even you could have googled your answer: One simple way is to use the Apache Http Components

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://localhost/users/Robert.WHATEVER");
HttpResponse response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 404) {
   System.out.println("User Robert.WHATEVER not found");
}

有一个很好的教程,其中包含许多解释如何使用HttpClient的示例。

There is a good Tutorial with many examples which explains how to use the HttpClient.

另一个高级框架是 ResteasyClientFramework

Another highlevel framework is the ResteasyClientFramework.