gpt4 book ai didi

dart - 如何使用SecureSocket修复HandshakeException?

转载 作者:行者123 更新时间:2023-12-03 03:02:53 31 4
gpt4 key购买 nike

我正在尝试连接到学校的Intranet。可以与Dart以外的其他任何设备连接(在Python,PHP中以及curl -s -L "https://intra.42.fr/?format=json"等)。

但是Dart VM认为我学校使用的TLS证书不好。使用此代码:

# pubspec.yaml
name: handshake-fail
dependencies:
http: any

import 'package:http/http.dart' as http;

main() {
var client = new http.Client();
client.post('https://intra.42.fr/?format=json', body: {"login": "test", "password": "test"})
.then((response) => print(response.body)
);
}

我得到以下异常:
Uncaught Error: HandshakeException: Handshake error in client (OS Error: Peer's Certificate issuer is not recognized., errno = -8179)
Unhandled exception:
HandshakeException: Handshake error in client (OS Error: Peer's Certificate issuer is not recognized., errno = -8179)
#0 _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:async/zone.dart:700)
#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#2 _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#3 _asyncRunCallback (dart:async/schedule_microtask.dart:36)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:119)

问题 Bypass Certificate Error Using Http指向错误报告 that suggests:

Optional parameters to [SecureSocket].initialize let you specify a certificate database (a directory containing cert9.db and key4.db), and whether or not to use the builtin well-known authorities.



我的问题是, 该怎么做?

最佳答案

我想你在找这个

var cl = new HttpClient();
cl.badCertificateCallback = () => print(x);
badCertificateCallback的dartdoc
* Sets a callback that will decide whether to accept a secure connection
* with a server certificate that cannot be authenticated by any of our
* trusted root certificates.

关于dart - 如何使用SecureSocket修复HandshakeException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22717561/

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