Flutter电影目录应用SSL Pinning出现HandshakeException求助
Flutter TMDb API SSL Pinning 证书验证失败问题
我正在基于https://api.themoviedb.org/3/开发Flutter电影目录应用,学习SSL Pinning时遇到证书验证失败错误,具体错误信息如下:
Exception has occurred.
HandshakeException (HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393)))
我尝试切换过Google和Cloudflare DNS,结果没有变化。
我的实现代码如下:
static const BASE_URL = 'https://api.themoviedb.org/3'; Future<SecurityContext> get globalContext async { try { final sslCert = await rootBundle.load('certificates/certificates.pem'); print('Certificate loaded successfully.'); SecurityContext securityContext = SecurityContext(withTrustedRoots: false); securityContext.setTrustedCertificatesBytes(sslCert.buffer.asInt8List()); return securityContext; } catch (e) { print('Error loading certificate: $e'); rethrow; } } @override Future<List<MovieModel>> getNowPlayingMovies() async { HttpClient client = HttpClient(context: await globalContext); client.badCertificateCallback = (X509Certificate cert, String host, int port) => false; IOClient ioClient = IOClient(client); final response = await ioClient.get(Uri.parse('$BASE_URL/movie/now_playing?$API_KEY')); if (response.statusCode == 200) { return MovieResponse.fromJson(json.decode(response.body)).movieList; } else { throw ServerException(); } }

内容的提问来源于stack exchange,提问作者Ibrahim
相关产品推荐
相关产品推荐

