.Content возвращает значение NULL - PullRequest
0 голосов
/ 14 ноября 2018

Я пытаюсь подключиться к 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

1 Ответ

0 голосов
/ 15 ноября 2018

Решением было добавить эту строку над новым RestClient (...)

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

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

...