使用RestSharp请求具有Windows身份验证的URL

时间:2017-11-28 14:49:33

标签: asp.net asp.net-mvc restsharp

我在IIS中有一个网站,其身份验证模式设置为Windows 我需要使用restsharp

在该网站中调用网址
var client = new RestClient(item.Url);
var request = new RestRequest("/account/Menu", Method.GET);
request.AddParameter("SSO_Token", token);
client.PreAuthenticate = false;
client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator(new NetworkCredential(username, password, domain));
// I also tried following codes with no luck:
// client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator();
// client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator(username, password);
var response = client.Execute(request);

现在问题是我收到了这个错误:

HTTP Error 401.1 - Unauthorized
You do not have permission to view this directory or page using the credentials that you supplied.

我确定提供的凭据是正确的。

1 个答案:

答案 0 :(得分:0)