如何从.NET(C#)应用程序发送带有Negotiate Authorization标头属性的HTTP请求?
我尝试了以下操作,但未将授权属性添加到请求中...
...
string url = ...;
WebRequest request = WebRequest.Create(url);
request.Credentials = GetCredential();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
...
private CredentialCache GetCredential()
{
string url = ...;
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new System.Uri(url), "Ntlm", new NetworkCredential(username, pwd, domain));
return credentialCache;
}
答案 0 :(得分:1)
我在WebRequest中使用网络凭据的经验是request.GetResponse()
除非从服务器收到未授权(质询)响应,否则不会传递凭据。如果它确实收到403,它将自动触发包含凭证的第二个请求。如果缺少Auth标头,请确保您要击中的终点返回401。