2

I launch my app on older version of Android - 5.1 and I am getting this error:

Unhandled Exception: HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: certificate has expired(handshake.cc:393))

On newer Android like 10 this is not appearing. I am making POST request to my backend, how to fix it?

I found solution: enter link description here

1 Answers1

7

Try this one

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

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

I am not sure about flutter web but it may help flutter ios and android.

Arjun Ranjith
  • 209
  • 1
  • 5
  • 2
    I am using the suggested solution, but I am getting this error: "MyHttpOverrides.createHttpClient' ('HttpClient Function(SecurityContext)') isn't a valid override of 'HttpOverrides.createHttpClient' ('HttpClient Function(SecurityContext?)')." which got solved by --> Change SecurityContext to SecurityContext?. – Shima K Oct 17 '22 at 19:25