获取ntlm令牌(www-authenticate-标头)

时间:2019-09-23 11:07:52

标签: c# rest authentication

使用Windows登录(NTLM)对Web服务(REST)进行C#身份验证很容易(如下面的示例所示),但是有什么方法可以输出NTLM令牌(“ www-authenticate”标头)?

using System;
using System.Net;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string URL_status = "http://localhost/status";

            CredentialCache myCache = new CredentialCache();
            myCache.Add(new Uri(URL_status), "NTLM", new NetworkCredential("username", "password", "domain"));

            WebClient WebClient = new WebClient();
            WebClient.Credentials = myCache;

            for (int i = 1; i <= 5; i++)
            {
                string Result = WebClient.DownloadString(new Uri(URL_status));
                Console.WriteLine("Try " + i.ToString() + ": " + Result);
            }

            Console.Write("Done");
            Console.ReadKey();
        }
    }


}

0 个答案:

没有答案