.内容返回NULL



我正在尝试连接到API。我遵循了文档,但是.Content返回NULL。有人能帮我弄清楚原因吗?我的目标是.NET 4.5.2,并使用最新版本的RestSharp(106.5.4(。

    var tokenclient = new RestClient("[api url]");
    var tokenrequest = new RestRequest(Method.POST);
    tokenrequest.AddParameter("undefined", "client_id=xxx&client_secret=xxx&grant_type=client_credentials", ParameterType.RequestBody);
    tokenrequest.AddHeader("cache-control", "no-cache");
    tokenrequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
    tokenrequest.AddHeader("grant_type", "client_credentials");
    IRestResponse tokenreceived = tokenclient.Execute(tokenrequest);
    var content = tokenreceived.Content; <-- .Content is returning NULL

解决方案是在新的RestClient(…(之上添加此行

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; 
        var tokenclient = new RestClient("[api-url]");

https://github.com/restsharp/RestSharp/issues/942

相关内容

  • 没有找到相关文章

最新更新