current position:Home>Fluent ignores authentication of HTTPS and WSS certificates

Fluent ignores authentication of HTTPS and WSS certificates

2022-05-15 01:31:07TenTenXu

Use Dio Ignore alone Https Certificate validation

Dio _dio = Dio();
_dio.options.baseUrl = UrlConfig.BASE_URL;
    _dio.options.connectTimeout = 5000;
    _dio.options.receiveTimeout = 3000;
    // Ignore Https check 
    (_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (HttpClient client) {
      client.badCertificateCallback =
          (X509Certificate cert, String host, int port) {
        return true;

Ignore the whole situation Https Certificate validation

Due to the needs of the project , Ignore when using Https After certificate verification , Connect websocket Is used in wss Address , Therefore, you also need to ignore certificate verification , Otherwise it will be reported CERTIFICATE_VERIFY_FAILED error , The way is as follows :

class GlobalHttpOverrides extends HttpOverrides {
  HttpClient createHttpClient(SecurityContext context) {
    // TODO: implement createHttpClient
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;

When you use it , stay main Method calls = GlobalHttpOverrides();

If you need to set the global , There is no need to separate dio Set certificate ignore ;
in addition , I use websocket Connection library is web_socket_channel: ^1.1.0; Ignore certificate validation for global , Personally, I don't think it's very good , Is there another way to connect websocket when , Ignore certificate verification , Instead of realizing the effect through global neglect ???

Reference resources :how to solve flutter CERTIFICATE_VERIFY_FAILED error while performing a POST request?

copyright notice
author[TenTenXu],Please bring the original link to reprint, thank you.

Random recommended