簡體   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