来自.net的错误调用API“无法创建SSL/TLS安全频道”。
当调用某些API时,我会从下面的代码中获取“无法创建SSL/TLS安全频道”(可用于某些API),但仅在从Windows 2012 Server运行时。它在我的笔记本电脑上正常工作。我发现的另一件事是,我可以从服务器上称为邮递员的失败API罚款,但是如果我使用PowerShell,则会失败。
它似乎与.NET有关,但我尝试更新为.NET 4.8而没有任何成功。
对还要尝试什么想法?
Console.WriteLine("Make Reuest Starting");
if (!string.IsNullOrWhiteSpace(generalConfig?.ProxyAddress))
{
WebProxy webProxy = new WebProxy(generalConfig.ProxyAddress);
webProxy.Credentials = new NetworkCredential(generalConfig.ProxyUsername, generalConfig.ProxyPassword,
generalConfig.ProxyDomain);
WebRequest.DefaultWebProxy = webProxy;
}
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
WebRequest request = WebRequest.Create(apiUrl) as HttpWebRequest;
request.Timeout = 40000;
if (!(string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)))
{
request.Credentials = new NetworkCredential(username, password);
}
Console.WriteLine("Pre web request log");
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Console.WriteLine(response.StatusCode);
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responseData = reader.ReadToEnd();
//Console.WriteLine(responseData);
}
}
I'm getting the error "Could not create SSL/TLS secure channel" from the code below when calling certain APIs (it works for some APIs) but only when run from a Windows 2012 server. It works fine on my laptop. The other thing I have found is I can call the failing APIs fine from Postman from the server but if I use Powershell it fails.
It seems to be something related to .Net but I have tried updating to .Net 4.8 without any success.
Any thoughts on what else to try?
Console.WriteLine("Make Reuest Starting");
if (!string.IsNullOrWhiteSpace(generalConfig?.ProxyAddress))
{
WebProxy webProxy = new WebProxy(generalConfig.ProxyAddress);
webProxy.Credentials = new NetworkCredential(generalConfig.ProxyUsername, generalConfig.ProxyPassword,
generalConfig.ProxyDomain);
WebRequest.DefaultWebProxy = webProxy;
}
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
WebRequest request = WebRequest.Create(apiUrl) as HttpWebRequest;
request.Timeout = 40000;
if (!(string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)))
{
request.Credentials = new NetworkCredential(username, password);
}
Console.WriteLine("Pre web request log");
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Console.WriteLine(response.StatusCode);
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responseData = reader.ReadToEnd();
//Console.WriteLine(responseData);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论