尝试使用HttpWebRequest从特定图片托管服务商下载图片时出现错误
基础连接已关闭:发送时发生意外错误。
示例图片我正在尝试这样做:https://static.dyp.im/u1F6o6Q0SW/03b0aef5a48efec8ba3c1b59009e60e4.jpg
这是我正在使用的代码:
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(remoteFilename);
response = request.GetResponse();
错误会在GetResponse()
行上抛出。
使用浏览器下载图像。我也尝试使用浏览器使用的相同标头(用户代理,接受,连接等),但错误仍然存在。
答案 0 :(得分:1)
对于我使用fiddler看到的内容,我认为Web正在使用TLSv1.2。如果我没有错,使用tls v1.2你需要net 4.5,所以你至少需要visual studio 2012.尝试在你的项目中使用net 4.5并使用像
这样的东西ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate{
return true;
};