C# 在c中获取http web响应时出现异常

C# 在c中获取http web响应时出现异常,c#,iis,C#,Iis,我有以下代码: Stream remoteStream = null; // Create a request to the file we are downloading webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Timeout = System.Threading.Timeout.Infinite; webRequest.ReadWriteTimeout = System.Threading.Timeout

我有以下代码:

Stream remoteStream = null;
// Create a request to the file we are downloading
webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Timeout = System.Threading.Timeout.Infinite;
webRequest.ReadWriteTimeout = System.Threading.Timeout.Infinite;
// Set default authentication for retrieving the file
webRequest.Credentials = new NetworkCredential(username, password);
// Retrieve the response from the server
webResponse = (HttpWebResponse)webRequest.GetResponse();
// Ask the server for the file size and store it
Int64 fileSize = webResponse.ContentLength;
我确实使用IIS安装了一个web服务器,并在那里复制了文件。Create方法的参数是文件的完整路径,如http/abc.dat

我一次又一次地调用这个方法来下载这个文件夹中的所有文件。 该行:

webResponse = (HttpWebResponse)webRequest.GetResponse();
对前几个文件执行良好,然后开始给出异常
404协议错误。我在这里做错了什么。IIS服务器中是否有需要配置的内容?

我怀疑这与IIS配置有关。。。最可能的原因是,正如错误代码所示,您正在尝试下载不存在的文件。我已验证这些文件是否存在。我可以使用web浏览器访问这些文件。对并行http请求的数量有任何限制。