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 HttpClient DelegatingHandler 请求通过一系列管道 请求发送前和响应接收后被执行


下一篇:开源RPC框架Pigeon