春のRestTemplate
を使用してウェブサイトのヘッダーを取得できます。このような
何か:
RestTemplate restTemplate = new RestTemplate();
boolean pageExists = true;
HttpHeaders headers = null;
try {
headers = restTemplate
.headForHeaders("http://www.youtube.com");
} catch (RestClientException e) {
pageExists = false;
}
System.out.println(headers);
// {Location=[https://www.youtube.com/], Content-Length=[0], Expires=[Tue, 27 Apr 1971 19:44:06 EST], X-Content-Type-Options=[nosniff], P3P=[CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info."], Content-Type=[text/html; charset=utf-8], Cache-Control=[no-cache], X-XSS-Protection=[1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube], Date=[Sat, 04 Nov 2017 10:21:53 GMT], Server=[YouTube Frontend Proxy], Set-Cookie=[VISITOR_INFO1_LIVE=rbqBq4s5uxo; path=/; domain=.youtube.com; expires=Thu, 05-Jul-2018 22:14:53 GMT; httponly, YSC=2VLECOABq0U; path=/; domain=.youtube.com; httponly]}
ウェブサイトは、それが404エラーでのRuntimeExceptionをスローします存在しない場合。
このウェブページ。それは休憩の終点を持っていますか?軽量リクエストをポーリングするには、タイマーで 'RestTemplate'を使います。ヘルスチェックエンドポイントのようなものがあるかどうかを調べることをお勧めします。 –