gpt4 book ai didi

c# - 使用WebClient下载时出现操作超时错误

转载 作者:可可西里 更新时间:2023-11-01 16:52:17 24 4
gpt4 key购买 nike

我收到操作超时异常。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;

namespace Timer1
{
class Program
{
static void Main(string[] args)
{

Timer t = new Timer(TimerCallback, null, 0, 420000); // 7 minutes

}
private static void TimerCallback(Object o)
{


string url = string.Empty;
WebClient client = new WebClient();
url = @"http://myurl.com";
client.DownloadString(url);


}
}
}

有没有办法增加超时属性?请帮忙。

最佳答案

最简单的答案是使用 client.Timeout = 420000 ( WebRequest.Timeout ),但如果您打算使用计时器来实现,您不妨尝试异步版本。类似于 Set timeout for webClient.DownloadFile() 的内容

关于c# - 使用WebClient下载时出现操作超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14670261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com