HttpRequest 连接关闭错误

HttpRequest connection closed error

尝试使用 HttpWebRequest 从特定图像托管商下载图像时出现错误

The underlying connection was closed: An unexpected error occurred on a send.

我正在尝试的示例图片:https://static.dyp.im/u1F6o6Q0SW/03b0aef5a48efec8ba3c1b59009e60e4.jpg

这是我正在使用的代码:

HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(remoteFilename);
response = request.GetResponse();

错误在 GetResponse() 行抛出。

使用浏览器可以下载图像。我也尝试使用相同的 headers 浏览器使用(用户代理、接受、连接等),但错误仍然存​​在。

对于我所看到的使用 fiddler 的内容,我认为网络正在使用 TLSv1.2。如果我没记错的话,要使用 tls v1.2 你需要 net 4.5,所以你至少需要 visual studio 2012。尝试在你的项目中定位 net 4.5 并使用类似

的东西
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate{ 
          return true;
};