Flutter Error: HandshakeException: Handshake error in client (: CERTIFICATE_VERI

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

局部代码




import 'package:dio/dio.dart';
import 'package:dio_http2_adapter/dio_http2_adapter.dart';


/// POST请求:
void postHttp()  async {
  Dio dio = Dio(BaseOptions(
    baseUrl: 'https://example.com',
    validateStatus: (status) => true, // 忽略http状态码验证
  ))..httpClientAdapter = Http2Adapter(
    ConnectionManager(
      idleTimeout: Duration(seconds: 15000),
      // 给 HttpClient 配置 SSL
      onClientCreate: (_, clientSetting) =>
      clientSetting.onBadCertificate = (_) => true,
    ),
  );


  try {
    ///发送 FormData:
    FormData formData =
    FormData.fromMap({
     // 数据省略
    });
    ///发起 post
    final response = await dio.post("$baseUrl/xxx", data:formData);
    print(response.data.toString());
  } catch (e) {
    print("post请求失败  $e");
  }
}

你可能感兴趣的:(flutter)