C# - 请求被中止: 未能创建 SSL/TLS 安全通道。

在调用接口前设置TLS

HttpClient client = new HttpClient();
HttpContent httpContent = new FormUrlEncodedContent(dic);

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var responseAsString = client.PostAsync(Server + "/oauth2/token", httpContent).Result.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<TokenModel>(responseAsString);

 

posted @ 2023-03-07 16:15  jxw_29  阅读(827)  评论(0)    收藏  举报