skip to Main Content

Flutter – Dio (HttpClient) cannot set a self-signed trust certificate

Code snippet: ...... (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { SecurityContext securityContext = SecurityContext(withTrustedRoots: true); // securityContext.setTrustedCertificatesBytes(certBytes); securityContext.setTrustedCertificates('assets/ca-cert.crt'); HttpClient httpClient = HttpClient(context: securityContext); httpClient.badCertificateCallback = (X509Certificate cert, String host, int port) { return true; }; }; ...... Error prompt: Failed to…

VIEW QUESTION
Back To Top
Search