简体   繁体   中英

Download a file with password and username with C#

How would I write a script to download files from this site. Is it possible to supply the login and password with the url?

http://feeds.itunes.apple.com/feeds/epf/

Would I format the url like this?

WebClient Client = new WebClient();
Client.DownloadFile("http://feeds.itunes.apple.com/feeds/epf/v3/full/current/itunes20110511.tbz.md5?username=myusername&password=mypassword", @"C:\folder\file.md5");

Yes, just set the WebClient's Credentials property to a NetworkCredentials instance with the username/password. For example:

Client.Credentials = new System.Net.NetworkCredential("john", "password1234!");

Use WebClient.Credentials property to supply your credentials to the web site:

using (WebClient client = new WebClient()) {
    client.Credentials = new NetworkCredential(username, password);
    client.DownloadFile("http://feeds.itunes.apple.com/feeds/epf/v3/full/current/itunes20110511.tbz.md5", @"C:\folder\file.md5");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM