最近我一直在努力通过 API 在 TeamCity 中进行身份验证。我可以直接在浏览器中访问资源(http://usr:pw@teamcity:8111/httpAuth/app/rest/..),但这样做会以编程方式返回 401-未授权。
WebRequest request = WebRequest.Create("http://user:pwd@teamcity:8111/httpAuth/app/rest/projects");
request.Method = WebRequestMethods.Http.Get;
try
{
request.Timeout = Timeout.Infinite;
WebResponse response = request.GetResponse(); //Returns 401:Unauthorized
我可以毫无问题地使用 guestAuth( http://teamcity:8111/guestAuth/app/rest/projects ),所以 WebRequest 本身应该没有任何问题。
有人有想法吗?