【问题标题】:Exception Caught by Image Resource Service (handshake.cc:359)图像资源服务捕获的异常 (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,
                          ),
                         ),
                        )

【问题讨论】:

    标签: android flutter http dart


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2019-12-24
      • 2019-03-09
      • 2022-10-04
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2020-03-30
      相关资源
      最近更新 更多