【问题标题】:HandshakeException (HandshakeException: Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: certificate has expired))HandshakeException(HandshakeException:客户端握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED:证书已过期))
【发布时间】:2022-07-20 16:54:11
【问题描述】:

在创建 agora 视频通话应用程序时,我遇到了这样的错误

HandshakeException(HandshakeException:客户端握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED:证书已过期(handshake.cc:393)))

这是抛出错误的那一行

Response _response = await get(Uri.parse(link));

我的代码是

import 'dart:convert';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart'; 
class VedioCall extends StatefulWidget {
  String channelName = "test";
  VedioCall({required this.channelName});
  @override
  State<VedioCall> createState() => _VedioCallState();
}

class _VedioCallState extends State<VedioCall> {
 late final AgoraClient _client;
  bool _loading = true;
  String tempToken = "";

  @override
  void initState() {
    getToken();
    super.initState();
  }

  Future<void> getToken() async {
    String link =
        "https://Agora-Node-TokenServer.vinaym4.repl.co/access_token?channelName=${widget.channelName}";

    Response _response = await get(Uri.parse(link));
    Map data = jsonDecode(_response.body);
    setState(() {
      tempToken = data["token"];
    });
    _client = AgoraClient(
        agoraConnectionData: AgoraConnectionData(
          appId: "5a4c1108a1af4a76924c9461d120dc47",
          tempToken: tempToken,
          channelName: widget.channelName,
        ),
        enabledPermission: [Permission.camera, Permission.microphone]);
    Future.delayed(Duration(seconds: 1)).then(
      (value) => setState(() => _loading = false),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: _loading
            ? Center(
                child: CircularProgressIndicator(),
              )
            : Stack(
                children: [
                  AgoraVideoViewer(
                    client: _client,
                  ),
                  AgoraVideoButtons(client: _client)
                ],
              ),
      ),
    );
    ;
  }
} 

【问题讨论】:

  • 您这边好像有网络问题。我已经在我的 Windows 机器上测试了你的代码,它运行完美。你在测试什么平台?
  • UptimeRobot @lepsch

标签: flutter dart agora.io


【解决方案1】:

证书今天刚刚更改。看起来 Android 没有将初始日期正确读取为包含日期。我想如果你明天试试,它会起作用的。

解决方案 1

与此同时,您可以尝试在另一个平台上进行测试,例如 Windows,它正在工作。

解决方案 2

或者您可以使用以下命令覆盖证书验证:

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

并在main 方法中设置HttpOverrides.global,如下所示:

void main() {
  HttpOverrides.global = MyHttpOverrides();
  runApp(const MyApp());
}

【讨论】:

  • 好的先生明天试试
  • 谢谢@lepsch
猜你喜欢
  • 2021-07-13
  • 2022-06-16
  • 2019-07-22
  • 1970-01-01
  • 1970-01-01
  • 2013-08-02
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多