![](/img/trans.png)
[英]c# application with http interface needs to implement NTLM authentication
[英]C# to Teamcity NTLM Authentication failing
我無法通過NTLM從C#向Teamcity進行身份驗證。 它可以在瀏覽器中和Postman中使用。
啟用日志記錄后,它似乎進行了NTLM握手,但是隨后出現了以下401錯誤:
The token supplied to the function is invalid
To login manually go to "/login.html" page
示例代碼如下。 我不確定這是怎么回事。 它適用於基本身份驗證和包含httpAuth的修改后的URI。
string uri = "http://teamcityserver/ntlmAuth/action.html?add2Queue=SomeBuild";
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(uri), "NTLM", new NetworkCredential("user", "password")); // Have also tried default credentials
var req = HttpWebRequest.Create(uri);
req.Method = "POST";
req.Credentials = cc;
req.Headers.Add("Origin: http://teamcity");
得到它了! 缺少的因素是在往返NTLM期間客戶端未發送cookie。
添加此修復程序:
req.CookieContainer = new CookieContainer();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.