我正在尝试连接到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
答案 0 :(得分:0)
解决方案是将此行添加到新的RestClient(...)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var tokenclient = new RestClient("[api-url]");