WEB認証

using System.Net;

string url = @”http://~”;

NetworkCredential credentials =
  new NetworkCredential(
    userName: @”~”,
    password: @”~”,
    domain: @”~”);

// 資格情報格納クラス
CredentialCache cache = new CredentialCache();
cache.Add(
  uriPrefix: new Uri(uriString: url),
  authType: @”NTLM”,
  cred: credentials);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = cache;

request.AllowAutoRedirect = true;
request.CookieContainer = new CookieContainer(capacity: 5);

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
  Console.WriteLine(@”In”);
}

Console.WriteLine(@”Done”);
Console.ReadLine();