1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| using System;
using System.Net;
namespace SaveFile
{
public class Program
{
public static void Main()
{
string uri = "https://lesite.fr/fichier.pdf";
string savePath = @"C:\Users\mycomputer\Desktop\fichier.pdf";
string userName = "username";
string password = "password";
using (System.Net.WebClient wc = new System.Net.WebClient())
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
wc.Proxy = WebRequest.DefaultWebProxy;
wc.Credentials = new NetworkCredential(userName, password);
wc.DownloadFile(uri, savePath);
}
}
}
} |
Partager