I'm unable to authenticate with Teamcity from C# with NTLM. It works in the browser and with Postman.
With logging turned on it seems to do the NTLM handshake, but then settles on a 401 error with:
The token supplied to the function is invalid
To login manually go to "/login.html" page
Sample code is below. I'm not sure what's wrong here. It works with Basic authentication and a modified URI including httpAuth.
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");
Got it! The missing factor was that the cookies were not being sent by the client during the NTLM back-and-forth.
Adding this fixed it:
req.CookieContainer = new CookieContainer();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.