Flutter Dart 配置https

工程使用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)