Dio问题总结

1. 添加代理

Dio dio = Dio(_options)
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (client) {
      client.badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
      client.findProxy = (uri) {
        if (proxyIP == null || proxyIP.isEmpty) {
          return 'DIRECT';
        }
        return 'PROXY $proxyIP:$proxyPort';
      };
      return client;
    };

2.CERTIFICATE_VERIFY_FAILED问题

项目运行时报了如下错误:

HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: self signed certificate in certificate chain(handshake.cc:393))

解决方法:

Dio dio = Dio(_options)
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
        (client) {
      client.badCertificateCallback = (cert, host, port) {
        return true;
      };
    };

你可能感兴趣的:(#,Flutter,#,Dart,flutter,dio,flutter代理,CERTIFICATE,dart代理)