图像资源服务捕获的异常 (handshake.cc:359)
Posted
技术标签:
【中文标题】图像资源服务捕获的异常 (handshake.cc:359)【英文标题】:Exception Caught by Image Resource Service (handshake.cc:359) 【发布时间】:2022-01-04 05:24:59 【问题描述】:Flutter 无法加载我的图像并且出现错误,这是什么问题,我该如何解决? :
═══════ Exception caught by image resource service ══════════════════
Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: self signed certificate(handshake.cc:359))
我将 IOClient 用于 HttpClient
import 'package:cached_network_image/cached_network_image.dart';
IOClient get _client => IOClient(HttpClient()
..connectionTimeout = Duration(seconds: 30)
..idleTimeout = Duration(seconds: 30)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true);
CachedNetworkImage(
imageUrl: item.thumbnail,
fit: BoxFit.cover,
httpHeaders:
'Authorization':
'Bearer $authProvider.token',
,
errorWidget: (context, _, __) =>
Center(
child: Icon(
Icons.broken_image_rounded,
size: 28.0,
color: Colors.black54,
),
),
)
【问题讨论】:
【参考方案1】:在 main.dart 文件中,添加如下类:
class MyHttpOverrides extends HttpOverrides
@override
HttpClient createHttpClient(SecurityContext context)
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) = true;
并添加到主方法:
HttpOverrides.global = new MyHttpOverrides();
【讨论】:
以上是关于图像资源服务捕获的异常 (handshake.cc:359)的主要内容,如果未能解决你的问题,请参考以下文章
客户端中的 Flutter HTTPS 握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED:ok(handshake.cc:363))