gpt4 book ai didi

flutter - 握手异常(握手异常 : Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: certificate has expired))

转载 作者:行者123 更新时间:2023-12-05 02:27:41 24 4
gpt4 key购买 nike

在创建 agora 视频通话应用程序时出现这样的错误

HandshakeException (HandshakeException: Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: certificate has expired(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)
],
),
),
);
;
}
}

最佳答案

证书今天刚换过。看起来 Android 没有正确读取初始日期作为包含日期。我想如果你明天试试,它就会成功。

方案一

与此同时,您可以尝试在另一个正常运行的平台(如 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());
}

注意:这是一个安全风险,因为每个无效证书都将被接受。因此,在生产中请删除此代码。


Screenshot

关于flutter - 握手异常(握手异常 : Handshake error in client (OS Error:CERTIFICATE_VERIFY_FAILED: certificate has expired)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73048312/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com