Download file over HTTPS using .NET (dotnet)

后端 未结 3 1758
后悔当初
后悔当初 2021-01-16 00:41

I would like to download a file using VB.NET (preferably) or C# via HTTPS.

I have this code to download a file over plain HTTP:

Dim client As WebClie         


        
3条回答
  •  天涯浪人
    2021-01-16 01:30

    Try something like this

            WebClient wc = new WebClient();
            wc.UseDefaultCredentials = false;
    
            CredentialCache creds = new CredentialCache();
            creds.Add(new Uri(url), "Basic",new NetworkCredential(username, password, domain));
    
            wc.Credentials = creds;
            wc.Headers.Add(HttpRequestHeader.UserAgent,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;");
            //wc.Headers["Accept"] = "/";
    
            wc.DownloadFile(url,localpath);
    

提交回复
热议问题