2
如何從.NET(C#)應用程序發送帶有協商授權標頭屬性的HTTP請求?用「協商授權」發送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;
}
它返回401 :( –
我的歉意 - 我的意思是在我的迴應中說401,而不是403.你的服務應該自動發出第二個包含Authorization Header的請求,如果它收到401 – Theo