繁体   English   中英

使用C#下载带密码和用户名的文件

[英]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.

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