gpt4 book ai didi

flutter - 客户端握手错误 : CERTIFICATE_VERIFY_FAILED Self signed certificate in flutter

转载 作者:行者123 更新时间:2023-12-04 22:34:40 25 4
gpt4 key购买 nike

我正在从我的 flutter 应用程序发出 https 帖子请求。因为我在服务器中使用自签名 SSL 证书,所以当我点击 API 时,我收到状态码为 405,我无法连接,

如果我使用 HTTP 包,我会收到以下异常,

HandshakeException: Handshake error in client (OS Error: I/flutter ( 7107): CERTIFICATE_VERIFY_FAILED: self signed certificate(handshake.cc:352))

当我尝试使用 deo 包时,我得到 405 状态码,下面是它的代码,
Response response;
final Dio dio = Dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
return client;
};
response = await dio.post(loginURL, data: {"username": username, "password": password});
print(response.data.toString());
print(response.statusCode);

我试图通过制作来避免 SSL 握手
 client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;

仍然无法使用任何其他解决方案?

最佳答案

这对我有用

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

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

class MyApp extends StatelessWidget {
.....

关于flutter - 客户端握手错误 : CERTIFICATE_VERIFY_FAILED Self signed certificate in flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61505097/

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