When trying to download an image from a specific image hoster using HttpWebRequest I get the error
The underlying connection was closed: An unexpected error occurred on a send.
Example image I'm trying this: https://static.dyp.im/u1F6o6Q0SW/03b0aef5a48efec8ba3c1b59009e60e4.jpg
This is the code I'm using:
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(remoteFilename);
response = request.GetResponse();
The error gets thrown on the GetResponse()
line.
Downloading the image works using a browser. I also tried using the same headers a browser uses (User agent, Accept, Connection etc) but the error persists.
For what i've seen using fiddler, i think that web is using TLSv1.2. If i'm not wrong, to use tls v1.2 you need net 4.5, so you need at least visual studio 2012. Try targeting net 4.5 in your project and use something like
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate{
return true;
};