.Content 返回 NULL
.Content is returning 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
解决方案是在 new RestClient(...) 上面添加这一行
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var tokenclient = new RestClient("[api-url]");
我正在尝试连接到 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
解决方案是在 new RestClient(...) 上面添加这一行
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var tokenclient = new RestClient("[api-url]");