后面检测网站是否挂掉
用ajax发送同步请求来判断网站是否挂掉不能解决跨域访问的问题。。
可以在后台用定时任务去检测试
代码如下:
public void httpConnetion(String urlStr,AsformwebSite webSite) {
URL url = null;
try {
url = new URL(urlStr);
URLConnection URLconnection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) URLconnection;
int responseCode = httpConnection.getResponseCode();
System.out.println(responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {//HTTP_OK 为200
} else {
//oa提醒
addRemind(webSite);
//短信提醒
sendSm(webSite.getF5(),"网站'"+webSite.getF2()+"'出现异常,请检查网站服务!");
}
} catch (Exception e) {
//oa提醒
addRemind(webSite);
//短信提醒
sendSm(webSite.getF5(),"网站'"+webSite.getF2()+"'出现异常,请检查网站服务!");
}
}