C# 在webclient.ResponseHeaders之后使用webclient.DownloadFile时,会出现WebException超时

C# 在webclient.ResponseHeaders之后使用webclient.DownloadFile时,会出现WebException超时,c#,webclient,response-headers,downloadfile,webexception,C#,Webclient,Response Headers,Downloadfile,Webexception,我正在尝试创建自己的下载管理器。 当一个链接被添加到下载管理器时,我使用一个webclient从服务器获取它的信息。像这样 WebClient webClient = new WebClient(); webClient.OpenRead(link); string filename = webClient.ResponseHeaders["Content-Disposition"]; 之后,我使用DownloadFile下载该文件 FileInfo fileInfo = new FileIn

我正在尝试创建自己的下载管理器。 当一个链接被添加到下载管理器时,我使用一个webclient从服务器获取它的信息。像这样

WebClient webClient = new WebClient();
webClient.OpenRead(link);
string filename = webClient.ResponseHeaders["Content-Disposition"];
之后,我使用DownloadFile下载该文件

FileInfo fileInfo = new FileInfo(path);
if (!fileInfo.Exists)
{
    webClient.DownloadFile(link, path);
}
当我这样做的时候。我得到一个WebException超时。 但是,当我删除webClient.ResponseHeaders部分时。它永远不会得到超时异常。 我真的需要阅读内容配置,因为有些链接上没有文件名。
我甚至尝试使用不同的网络客户端下载并获取其信息,但结果相同。

我找到了另一种获取文件信息的方法,解决了这个问题

string Name = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(Link);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

for(int i=0; i < myHttpWebResponse.Headers.Count; i++)
{
    if (myHttpWebResponse.Headers.Keys[i] == "Content-Disposition")
    {
        Name = myHttpWebResponse.Headers[i];
    }
}
myHttpWebResponse.Close();
string Name=”“;
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(Link);
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
对于(int i=0;i