Flutter Web,向具有自签名证书的服务器发出请求时出现问题

标签 flutter ssl-certificate self-signed flutter-web

我面临着 Flutter Web 的第一个大问题。

我必须通过对具有自签名 ssl 证书的服务器的后期调用来使用 oauth2 登录。

使用 http 和 dio 客户端发出请求,我收到 net::ERR_CERT_AUTHORITY_INVALID。我在网上找到的唯一方法是使用 HttpClient,它适用于 android 和 IO,但 dart:io 在网络构建中不起作用。
有没有办法信任我的 flutter web ssl 证书?

       // My simple line of code
      var response = await client.post(authorizationEndpoint.toString(), body: body, headers: headers);
      // What I am looking for 
      var response = await client.post(authorizationEndpoint.toString(), 
                               body: body, headers: headers, 
                       --->    trustanyCA: true);

最佳答案

在网络版本中没有办法做到这一点。浏览器的 XMLHttpRequest只是不允许绕过不受信任的证书,尽管可以使用其他 http 客户端来做到这一点。

如果仅用于调试目的,您可以尝试将 SSL 证书添加到系统的受信任证书(对于 macOS,将其添加到 Keychain Access 中的系统证书),以及覆盖浏览器的安全选项。引用 this question了解如何在 Chrome 中覆盖它。

对于生产用途,您仍然需要可信的有效证书。

关于Flutter Web,向具有自签名证书的服务器发出请求时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60327664/

相关文章:

listview - flutter 。在非常大的 ListView 上设置 ListView 初始位置

dart - Flutter 小部件状态构造函数未运行

android - Google Maps Android API : Failed to load map. 联系 Google 服务器时出错。这可能是 SSL Pinning 实现后的身份验证问题

c++ - 如何通过 HttpReceiveHttpRequest() 使用 HTTPS?

vue.js - Nuxt.js/Axios 自签名证书错误

web-services - 如何在 postman 中测试https rest webservice

flutter - 自定义验证 TextFormField Flutter

flutter - 将图标保存为共同偏好设置

ssl - 关于 CSR 和 SSL 证书的问题

带 SSL 的 Android 应用程序