You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 16:48:14