本文整理汇总了C#中System.Net.WebClient.Credentials属性的典型用法代码示例。如果您正苦于以下问题:C# WebClient.Credentials属性的具体用法?C# WebClient.Credentials怎么用?C# WebClient.Credentials使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.Credentials属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
try {
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
Byte[] pageData = client.DownloadData("http://www.contoso.com");
string pageHtml = Encoding.ASCII.GetString(pageData);
Console.WriteLine(pageHtml);
} catch (WebException webEx) {
Console.Write(webEx.ToString());
}
}
示例2: Main
//引入命名空间
using System;
using System.Net;
using System.Text;
public class CredTest
{
public static void Main()
{
WebClient wc = new WebClient();
NetworkCredential nc = new NetworkCredential("alex", "mypassword");
wc.Credentials = nc;
byte[] response = wc.DownloadData("http://www.java2s.com/index.htm");
Console.WriteLine(Encoding.ASCII.GetString(response));
}
}