csharp
var client = new RestClient(url);
client.Timeout = -1;
var request = new RestRequest(Method.POST);
client.UserAgent = "Apifox/1.0.0 (https://apifox.com)";
request.AddHeader("Content-Type", "application/json");
//request.AddHeader("Authorization", "Bearer 123");
var body = @JsonData;
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
这是我的API调用代码,然后一开始提示:由于远程方已关闭传输流,身份验证失败。
我以为是因为Https 的原因:
所以添加代码来忽略SSL证书但是还是不行
csharp
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
于是想想应该可能是http协议的问题
于是
csharp
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
问题成功解决
分析原因应该是.Net 4.6以下版本协议固定的原因,升级.Net框架版本可以解决,或者可以上方指定协议的代码也可以解决