美文网首页
Flutter Dart 配置https

Flutter Dart 配置https

作者: Cloverss | 来源:发表于2020-07-11 15:48 被阅读0次

    工程使用dio,证书文件是.crt,如果使用HttpClient的,直接新建即可

        ByteData data = await rootBundle.load('assets/certificate/[certificateName].crt');
        (_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
          SecurityContext securityContext = new SecurityContext();
          securityContext.setTrustedCertificatesBytes(data.buffer.asUint8List());
          client = HttpClient(context: securityContext);
          return client;
        };
    

    替换[certificateName]你使用的https证书即可

    相关文章

      网友评论

          本文标题:Flutter Dart 配置https

          本文链接:https://www.haomeiwen.com/subject/znjicktx.html