利用PowerShell可以调用动态页面,然后再用 .bat 执行 PowerShell 脚本,最后把 .bat 添加到服务器的任务计划里面。OK,所有操作都做好了,.Net 定时执行了,是不是呢,有木有呢。
可能也有其他方法,比如用 WGet 等等,但是 推荐用 PowerShell ,为什么呢,因为 PowerShell 太强大呗
PowerShell 语法(demo1.ps1):
$date = Get-Date;
$beginTime = 2 * 60 ;
$endTime = 2 * 60 + 11;
$minuteCount = $date.hour * 60 + $date.minute
#if the time is right
if(($minuteCount -le $endTime ) -and ($minuteCount -ge $beginTime ))
{
#send request
$webClient = new-object System.Net.WebClient;
$webClient.Headers.Add("user-agent","PowerShell Script");
$beginTime = 2 * 60 ;
$endTime = 2 * 60 + 11;
$minuteCount = $date.hour * 60 + $date.minute
#if the time is right
if(($minuteCount -le $endTime ) -and ($minuteCount -ge $beginTime ))
{
#send request
$webClient = new-object System.Net.WebClient;
$webClient.Headers.Add("user-agent","PowerShell Script");
$webClient.Headers.Add("Referer","PowerShell Script");
$url = "http://cms.hujiang.com/enAdmin/Handler/Listen_cms.ashx?code=listen_cms_20111130876";
$message = $webClient.DownloadString($url);
#write log
write("Message:"+$message);
}
else
{
write("Not Update");
}
sleep 5
$message = $webClient.DownloadString($url);
#write log
write("Message:"+$message);
}
else
{
write("Not Update");
}
sleep 5
Bat 语法(demo1.bat):
powershell %~sdp0Listen-Cms.ps1
sleep 5
sleep 5