Sfoglia il codice sorgente

定时访问服务修改为支持访问多个地址

新疆警官学校中职
zhangli 1 anno fa
parent
commit
4bd4d7eae5
2 ha cambiato i file con 23 aggiunte e 10 eliminazioni
  1. +1
    -1
      Learun.Framework.Ultimate V7/VisitService/App.config
  2. +22
    -9
      Learun.Framework.Ultimate V7/VisitService/Service1.cs

+ 1
- 1
Learun.Framework.Ultimate V7/VisitService/App.config Vedi File

@@ -4,7 +4,7 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup> </startup>
<appSettings> <appSettings>
<!--长阳API地址-->
<!--长阳API地址,如有多个请用英文逗号隔开-->
<add key="cyapi" value="https://www.baidu.com/" /> <add key="cyapi" value="https://www.baidu.com/" />
</appSettings> </appSettings>
</configuration> </configuration>

+ 22
- 9
Learun.Framework.Ultimate V7/VisitService/Service1.cs Vedi File

@@ -55,16 +55,29 @@ namespace VisitService


System.GC.Collect(); System.GC.Collect();
var url = System.Configuration.ConfigurationManager.AppSettings["cyapi"].ToString(); var url = System.Configuration.ConfigurationManager.AppSettings["cyapi"].ToString();
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.KeepAlive = false;
myRequest.Method = "HEAD"; //设置提交方式可以为"get","head"等
myRequest.Timeout = 30000; //设置网页响应时间长度
myRequest.AllowAutoRedirect = false; //是否允许自动重定向
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
// return (myResponse.StatusCode == HttpStatusCode.OK);//返回响应的状态
var arr = url.Split(';');
foreach (var item in arr)
{
try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.KeepAlive = false;
myRequest.Method = "HEAD"; //设置提交方式可以为"get","head"等
myRequest.Timeout = 30000; //设置网页响应时间长度
myRequest.AllowAutoRedirect = false; //是否允许自动重定向
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
// return (myResponse.StatusCode == HttpStatusCode.OK);//返回响应的状态

System.IO.File.AppendAllText(logPath_timer,
"\r\n" + DateTime.Now + "\r\n访问结果:" + myResponse.StatusCode);
}
catch (Exception ex)
{
System.IO.File.AppendAllText(logPath_timer,
"\r\n" + DateTime.Now + "\r\n访问结果异常,异常信息:" + ex.Message + ",访问地址:" + item);
}
}


System.IO.File.AppendAllText(logPath_timer,
"\r\n" + DateTime.Now + "\r\n访问结果:" + myResponse.StatusCode);
} }
catch (Exception ex) catch (Exception ex)
{ {


Caricamento…
Annulla
Salva