How to download a file from http and https in C# on windows server 2012 and windows 7

Mojtaba_Hakim 281 Reputation points
2021-08-17T04:26:37.05+00:00

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

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,580 questions
{count} votes