我尝试使用颤振应用程序连接到Mongodb并且它正在抛出证书错误

”’我尝试使用颤振应用程序连接到 Mongodb 数据库并且它正在抛出证书错误,我也尝试添加 MyHttpOverrides 但没有修复。错误是=>“HandshakeException(HandshakeException:客户端握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED: 无法获取本地颁发者证书(handshake.cc:393)))”

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:projectv/routes/routes.dart';
import 'package:projectv/screens/home.dart';
import 'package:projectv/screens/property_detail.dart';
import 'package:projectv/utitlity/mongo_db.dart';
import './screens/agent.dart';
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  HttpOverrides.global = MyHttpOverrides();
  await MongoDbConnection.dbConnect();
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      statusBarColor: Color.fromARGB(255, 83, 167, 236), // status bar color
    ),
  );
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Zulu real estate',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const Home(),
        routes: {
          Routes.propertyDetails: (context) => PropertyDetail(),
          Routes.propertyAgent: (context) => AgentScreen(),
        });
  }
}
class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

”’导入’package:mongo_dart/mongo_dart.dart’;

class MongoDbConnection {
  static var dbUrl, dbCollection;
  static dbConnect() async {
    dbUrl = await Db.create(
        "mongodb+srv://abdi:abdi@cluster0.soti0.mongodb.net/myFirstDatabase?retryWrites=true&w=majority");
    await dbUrl.open(secure: true);
    dbCollection = dbUrl.collection("agents");
  }
}

”’

© 版权声明
THE END
喜欢就支持一下吧
点赞146 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片