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

标签 c# api security ssl httpwebrequest

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

请求已中止:无法创建 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/

相关文章:

c# - 结构图范围/生命周期指南?

c# - 为什么 EF6 不支持 ` ignore ` 实体属性(复杂属性)Fluent API 的属性?

c# - 使用 Revit API 在模型中放置自定义体量族实例

java - OpenOffice API : How to turn off headers and footers

security - Rails 5 - 谁能解释一下从未经净化的请求参数生成 URL 是如何不安全的?

c# - 我可以在 AutoMapper 中集中我想忽略的映射吗?

javascript - 有没有办法在前端 Web 应用程序中使用 Twitter API?

Angular:HTTP GET 请求 - 选项 405(不允许方法)

android - GmsCore_OpenSSL 会导致所有更新的应用程序被 Google Play 拒绝吗?

security - 危险代码片段应该如何发布?