[英]Download a file with password and username with C#
如何编写脚本以从此站点下载文件。 是否可以通过URL提供登录名和密码?
http://feeds.itunes.apple.com/feeds/epf/
我会像这样格式化网址吗?
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");
是的,只需使用用户名/密码将WebClient's
Credentials
属性设置为NetworkCredentials
实例。 例如:
Client.Credentials = new System.Net.NetworkCredential("john", "password1234!");
使用WebClient.Credentials属性为网站提供凭据:
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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.