c#webclient的download方法超时问题
privatestringGetFileList(stringUrl){WebClientFileList=newWebClient();byte[]FileListDa...
private string GetFileList(string Url)
{
WebClient FileList = new WebClient();
byte[] FileListDataBuffer = FileList.DownloadData(Url);
return Encoding.Default.GetString(FileListDataBuffer);
}
private string GetCommand(string Url)
{
WebClient Command = new WebClient();
byte[] CommandBuffer = Command.DownloadData(Url);
return Encoding.Default.GetString(CommandBuffer);
}
以上两个方法都是获取网页上的代码,获取的是不同的网页。我用timer去监视网页的代码,但是只要一个方法运行,另一个方法就不运行了,提示超时连接,请问怎么解决,小弟不懂,请说详细点,只要问题解决,分数大大的有 展开
{
WebClient FileList = new WebClient();
byte[] FileListDataBuffer = FileList.DownloadData(Url);
return Encoding.Default.GetString(FileListDataBuffer);
}
private string GetCommand(string Url)
{
WebClient Command = new WebClient();
byte[] CommandBuffer = Command.DownloadData(Url);
return Encoding.Default.GetString(CommandBuffer);
}
以上两个方法都是获取网页上的代码,获取的是不同的网页。我用timer去监视网页的代码,但是只要一个方法运行,另一个方法就不运行了,提示超时连接,请问怎么解决,小弟不懂,请说详细点,只要问题解决,分数大大的有 展开
2个回答
展开全部
webclient 连接数限制默认是2 , 可以通过ServicePointManager.DefaultConnectionLimit修改
ServicePointManager.DefaultConnectionLimit=10//可以同时开10个
重写Webclient的GetWebRequest方法,为HttpWebRequest添加请求超时及读写超时
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
request.Timeout = 1000 * Timeout;
request.ReadWriteTimeout = 1000 * Timeout;
return request;
}
ServicePointManager.DefaultConnectionLimit=10//可以同时开10个
重写Webclient的GetWebRequest方法,为HttpWebRequest添加请求超时及读写超时
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
request.Timeout = 1000 * Timeout;
request.ReadWriteTimeout = 1000 * Timeout;
return request;
}
追问
明显是错的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询