[英]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.