C# 用于登录的LTPA令牌无效-Maximo Rest API

C# 用于登录的LTPA令牌无效-Maximo Rest API,c#,dotnet-httpclient,maximo,ltpa,C#,Dotnet Httpclient,Maximo,Ltpa,我正在构建一个访问Maximo Rest API的应用程序,我使用这段代码调用API 我正在使用.NETFramework4.5C# 正如您所看到的,我正在使用cookie容器捕获在进行身份验证时随响应发送的cookie。Authenticate()有效。它返回一个302,带有一个LTPA令牌。但是GET请求失败。我得到这个错误: 用于登录的LTPA令牌无效。启用WebSphere Application Server安全性时,LTPA令牌用于登录过程。请等待几秒钟,然后再次尝试登录。如果问题仍

我正在构建一个访问Maximo Rest API的应用程序,我使用这段代码调用API

我正在使用.NETFramework4.5C#

正如您所看到的,我正在使用cookie容器捕获在进行身份验证时随响应发送的cookie。Authenticate()有效。它返回一个302,带有一个LTPA令牌。但是GET请求失败。我得到这个错误:

用于登录的LTPA令牌无效。启用WebSphere Application Server安全性时,LTPA令牌用于登录过程。请等待几秒钟,然后再次尝试登录。如果问题仍然存在,请清除浏览器cookie或重新启动浏览器

当我使用Postman时,我会遇到类似的错误,但当我再次尝试请求时,它会起作用

我交换了框架,使用了.NETCore2.1。完全相同的代码没有任何问题


为什么这适用于.NETCore而不是.NETFramework?使用.NETCore并不能解决我的问题,它必须是.NET4.5。有人能帮我解决这个问题吗?

这不是答案,但是,实现重试调用可以解决这个问题。我仍然想知道为什么这是必要的。
public class MaximoClient
{

    private string ServerURL;
    private string AuthUsername;
    private string AuthPassword;
    private CookieContainer cookieContainer = null;

    private string HttpGetRequest(string URL)
    {
        string ResponseContent;
        try
        {
            if (this.cookieContainer == null)
            {
                this.Authenticate();
            }


            HttpClientHandler handler = new HttpClientHandler
            {
                CookieContainer = this.cookieContainer
            };
            HttpClient client = new HttpClient(handler);

            HttpRequestMessage Request = new HttpRequestMessage
            {
                RequestUri = new Uri(URL, UriKind.Absolute),
                Method = HttpMethod.Get
            };


            var Response = client.SendAsync(Request).Result;
            ResponseContent = Response.Content.ReadAsStringAsync().Result;
        }
        catch (Exception e)
        {
            throw e;
        }

        return ResponseContent;
    }



    private void Authenticate()
    {
        try
        {
            this.cookieContainer = new CookieContainer();
            HttpClientHandler handler = new HttpClientHandler
            {
                CookieContainer = cookieContainer,
                AllowAutoRedirect = false,
                UseCookies = true,

            };

            this.Client = new HttpClient(handler);

            HttpClient client = this.Client;

            HttpRequestMessage Request = new HttpRequestMessage
            {
                RequestUri = new Uri($"{this.ServerURL}/oslc/j_security_check", UriKind.Absolute),
                Method = HttpMethod.Post
            };
            var postData = Encoding.ASCII.GetBytes($"j_username={this.AuthUsername}&j_password={this.AuthPassword}");
            Request.Content = new ByteArrayContent(postData);
            Request.Content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");


            HttpResponseMessage Response = client.SendAsync(Request).Result;

            string ResponseContent = Response.Content.ReadAsStringAsync().Result;

            int code = (int)Response.StatusCode;
            if (code > 399)
            {
                throw new Exception("HttpWebRequest returned Status Code:" + Response.StatusCode + " : " + Response.ReasonPhrase);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
    }

}