此代码在使用.net Framework 4.6.2的Windows窗体应用程序中可以正常运行,但是当我将其用作控制台应用程序时,可以从任务计划程序中运行它,但没有任何结果。我想我在翻译中失去了一些东西。
RestClient restClient = new RestClient("https://api.vault.com");
string refreshToken = @"abc";
string encodedClientIdSecret = Base64Encode("AP-123");
string responseStr = "";
string url = "/v1/OAuth";
dynamic jsonObj = "";
RestRequest request = new RestRequest(url, Method.POST);
request.AddHeader("Authorization", encodedClientIdSecret);
request.AddParameter("grant_type", "refresh_token");
request.AddParameter("refresh_token", refreshToken);
IRestResponse response;
restClient.Execute(request);
response = restClient.Execute(request);
Console.WriteLine(response.Content + " || " + encodedClientIdSecret);
Console.ReadKey();
jsonObj = JsonConvert.DeserializeObject(response.Content);
responseStr = jsonObj.access_token;
return responseStr;
它基本上告诉我该值不能为null,当我查看response.Content时,我什么也没得到,状态码返回为“ 0”。有什么想法吗?
答案 0 :(得分:0)
只需添加:
//Required For SSL/TLS Error Start
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//Required For SSL/TLS Error End
我得到了结果。希望这对其他人有帮助!