Flutter Dart 配置https

2020-07-11  本文已影响0人  Cloverss

工程使用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证书即可

上一篇下一篇

猜你喜欢

热点阅读