我有这种方法从API获取数据并将其保存到JSON文件中。C#在一段时间间隔内运行的方法
如何获取JSON文件在小时内每小时更新一次。
public void saveUsers()
{
string uri = "https://****dd.harvestapp.com/people";
using (WebClient webClient = new WebClient())
{
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.Headers[HttpRequestHeader.Accept] = "application/json";
webClient.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(new UTF8Encoding().GetBytes(usernamePassword));
string response = webClient.DownloadString(uri);
File.WriteAllText(jsonPath, response);
}
}
你的主机是什么类型的? Winforms?安慰?网站? – user3185569
我使用mvc。 –
你可以试试[FluentScheduler](https://github.com/fluentscheduler/FluentScheduler) –