我正在尝试连接到我校的内部网。可以使用除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:
[
SecureSocket
].initialize
的可选参数允许您指定证书数据库(包含cert9.db
和key4.db
的目录),以及是否使用内置井知名当局。
我的问题是,该怎么做?
答案 0 :(得分:1)
我认为你正在寻找这个
var cl = new HttpClient();
cl.badCertificateCallback = () => print(x);
badCertificateCallback
* 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.