How to download a file from http and https in C# on windows server 2012 and windows 7
Mojtaba_Hakim
281
Reputation points
I'm trying to download this file AnyDesk.zip from a URL in windows server 2012 and windows 7
CS Code :
using System;
using System.Net;
namespace ConsoleApp3
{
class Program
{
public static string saveLoc = @"AnyDesk.zip";
static void Main(string[] args)
{
//1-//First Try---------------------------------------------
using (WebClient wc = new WebClient())
{
wc.DownloadFile(
// Param1 = Link of file
new System.Uri("https://ghaemcoarsh.com/AnyDesk.zip/"),
// Param2 = Path to save
@"AnyDesk.zip"
);
}
//2-//Secound Try---------------------------------------------
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
string url = @"https://ghaemcoarsh.com/AnyDesk.zip/";
using (WebClient wc = new WebClient())
{
byte[] fileBytes = wc.DownloadData(url);
string fileType = wc.ResponseHeaders[HttpResponseHeader.ContentType];
System.IO.File.WriteAllBytes(saveLoc, fileBytes);
}
//3-//Third Try---------------------------------------------
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("https://ghaemcoarsh.com/AnyDesk.zip/");
request.Method = "GET";
var response = request.GetResponse();
var contenttype = response.Headers[".zip"];
var stream = response.GetResponseStream();
Console.ReadKey();
}
}
}
but its have error in windows 2012 :
The request was aborted: Could not create SSL/TLS secure channel
But in Windows 7 strangely the file download is incomplete
I tried all way that was in internet about this but its not working
please help me