WebApi 模拟Windows认证

2021/12/27 7:07:43

本文主要是介绍WebApi 模拟Windows认证,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.使用当前登录用户

HttpClientHandler hch = new HttpClientHandler();

hch.UseDefaultCredentials = true;  

2.使用账户密码,模拟任何账户

HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential("username", "password", "demain");
using (HttpClient client = new HttpClient(handler))
{
HttpResponseMessage response = client.GetAsync("http://localhost/webapi/api/demo").Result;
IEnumerable<string> userNames = response.Content.ReadAsAsync<IEnumerable<string>>().Result;
foreach (string userName in userNames)
{
Console.WriteLine(userName);
}
}
Console.Read();



这篇关于WebApi 模拟Windows认证的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程