gpt4 book ai didi

c# - 无法修复 "Could not create SSL/TLS secure channel"发出 web 请求

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:52 24 4
gpt4 key购买 nike

我正在尝试从在虚拟机上运行的本地主机项目发出网络请求。问题是我无法创建网络请求,我将收到以下错误:

请求已中止:无法创建 SSL/TLS 安全通道”。

当我尝试使用 Postman(也来 self 的虚拟机)访问我在 webrequest 中调用的相同 API 时,它确实有效:

这行不通:

网络请求代码:

try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://pokeapi.co/api/v2/pokemon/ditto/");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject(responseBody);

}
catch (Exception ex)
{

throw ex;
}

响应:

enter image description here

这确实有效:

enter image description here

我已经尝试过的:

我已经搜索了这个错误以及所有添加以下代码行的解决方案:

 ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;

希望有人能帮忙,

提前致谢!

最佳答案

终于修好了!

因为我尝试调用的 API 是 https 而我自己的应用程序是 http,所以导致错误!

关于c# - 无法修复 "Could not create SSL/TLS secure channel"发出 web 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56257375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com