某些服务器的C#WebClient异常

时间:2018-11-17 18:27:24

标签: c# webclient

我的完整代码是:

using System;
using System.IO;
using System.Net;
namespace Hello
{
    public class Program
    {
        public static void Main()
        {
            WebClient web = new WebClient();
            web.DownloadFile("https://images.wallpaperscraft.com/image/fractal_spiral_digital_art_130384_1280x720.jpg", "1.jpg");
            web.DownloadFile("https://b8.eu.icdn.ru/a/a_l_e_x/5/61846275zQa.jpg", "2.jpg");
        }
    }
}

可以很好地下载图像“ 1.jpg”。但是下一个链接会导致此异常:

未处理的异常:System.Net.WebException:基础连接已关闭:发送时发生意外错误。 ---> System.IO.IOException:无法从传输连接中读取数据:现有连接被远程主机强行关闭。 ---> System.Net.Sockets.SocketException:**在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags中,远程主机强行关闭了现有连接** )在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)-内部异常堆栈跟踪的结尾-在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,位于System.Net.FixedSizeReader.ReadPacket(Byte []缓冲区,Int32偏移量,Int32计数),位于System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocolRequest asyncRequest),位于System.Net System.Net.Security.SslState.StartSendBlob(在System.Net.Security.SslState.ForceAuthentication处的字节[]传入,Int32计数,AsyncProtocolRequest asyncRequest)的.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken消息,AsyncProtocolRequest asyncRequest) []缓冲区,位于System.Net.Security.SslState.ProcessAut中的AsyncProtocolRequest asyncRequest) System.Net.TlsStream.CallProcessAuthentication(对象状态)处于System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值saveSyncCtx)处于System.Threading.ExecutionContext.Run(ExecutionContext执行上下文, ContextCallback回调,对象状态,布尔值saveSyncCtx)位于System.Net.TlsStream.Write(Byte [] [ ]缓冲区,Int32偏移量,Int32大小)在System.Net.PooledStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)在System.Net.ConnectStream.WriteHeaders(布尔异步)-内部异常堆栈跟踪的结尾->


请注意,我可以在任何网络浏览器中查看第二张图像,而不会出现错误。我可以使用任何下载管理器下载它。

0 个答案:

没有答案