调用 AuthenticateWithApiKey 后调用 RestApi returns "NotAuthorized" AuthenticationState

Rally RestApi returns "NotAuthorized" AuthenticationState after call to AuthenticateWithApiKey

我得到的结果与以下代码不一致:

RallyRestApi myRestApi = new RallyRestApi();
myRestApi.AuthenticateWithApiKey("<my_api_key>");

大多数情况下,myRestApi.AuthenticationState 是在上述代码 运行 之后的 RallyRestApi.AuthenticationResult.Authenticated,我的应用程序运行良好。但是偶尔,上面的代码是运行之后,myRestApi.AuthenticationState就是RallyRestApi.AuthenticationResult.NotAuthorized。我曾尝试查看 myRestApi 属性,但我没有想到要调查为什么调用 AuthenticateWithApiKey returns NotAuthorized。即使是这样,我的解决方案是什么,以便我每次都能可靠地进行身份验证?

提前致谢!

您需要在身份验证请求中显式传递 serverURI,而不是依赖默认值:

RallyRestApi restApi = new RallyRestApi();
restApi.AuthenticateWithApiKey("myApiKey", new Uri("https://rally1.rallydev.com"));