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;
};