Csharp/C Sharp by API/System.Net/CredentialCache — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
CredentialCache.Add
using System;
using System.Net;
using System.Text;
public class CredCacheTest
{
public static void Main()
{
WebClient wc = new WebClient();
string website1 = "http://remote1.ispnet.net";
string website2 = "http://remote2.ispnet.net";
string website3 = "http://remote3.ispnet.net/login";
NetworkCredential nc1 = new NetworkCredential("m", "g");
NetworkCredential nc2 = new NetworkCredential("e", "s", "home");
NetworkCredential nc3 = new NetworkCredential("a", "d");
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(website1), "Basic", nc1);
cc.Add(new Uri(website2), "Basic", nc2);
cc.Add(new Uri(website3), "Digest", nc3);
wc.Credentials = cc;
wc.DownloadFile(website1, "website1.htm");
wc.DownloadFile(website2, "website2.htm");
wc.DownloadFile(website3, "website3.htm");
}
}
new CredentialCache()
using System;
using System.Net;
using System.Text;
public class CredCacheTest
{
public static void Main()
{
WebClient wc = new WebClient();
string website1 = "http://remote1.ispnet.net";
string website2 = "http://remote2.ispnet.net";
string website3 = "http://remote3.ispnet.net/login";
NetworkCredential nc1 = new NetworkCredential("m", "g");
NetworkCredential nc2 = new NetworkCredential("e", "s", "home");
NetworkCredential nc3 = new NetworkCredential("a", "d");
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(website1), "Basic", nc1);
cc.Add(new Uri(website2), "Basic", nc2);
cc.Add(new Uri(website3), "Digest", nc3);
wc.Credentials = cc;
wc.DownloadFile(website1, "website1.htm");
wc.DownloadFile(website2, "website2.htm");
wc.DownloadFile(website3, "website3.htm");
}
}