Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从url下载pdf_C#_Asp.net - Fatal编程技术网

C# 从url下载pdf

C# 从url下载pdf,c#,asp.net,C#,Asp.net,我正在尝试从几个网站下载PDF。我无法成功地从任何URL下载它们 foreach (string url in urls) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (var client = new WebClient()) { byte[] file

我正在尝试从几个网站下载PDF。我无法成功地从任何URL下载它们

        foreach (string url in urls)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            using (var client = new WebClient())
            {

                byte[] filedata = client.DownloadData(url);

                using (MemoryStream ms = new MemoryStream(filedata))
                {

                }
            }

        }
我在谷歌上搜索了很多,大多数帖子都提到了某种SSL问题。我添加了SecurityProtocolType.Tls12(并尝试使用ssl3)。这些网站大多是知名网站(例如dropbox)。 我也尝试过使用
HttpClient
。 我也尝试过使用
DownloadFile

我得到的例外情况如下:

IOException:无法从传输连接读取数据:远程主机强制关闭了现有连接。1/2

SocketException:远程主机2/2强制关闭了现有连接

此异常最初是在此调用堆栈中引发的: System.Net.Sockets.Socket.Receive(字节[],int,int,System.Net.Sockets.SocketFlags) System.Net.Sockets.NetworkStream.Read(字节[],int,int)

有没有可能是因为尺寸问题?它们大多数的重量在5mb到20MB之间

更新:


在控制台应用程序中使用代码将正确下载文件。这可能是iis的问题吗?

您可能会受到速率限制。你是不是在短时间内提出了很多这样的要求?我看到你有一个
for
循环…我想他们有机器人控制。改用dcsoup库。假装你是以chrome用户的身份连接,我甚至一次都不能下载文件。我试试汤