Updated 27 October 2023
How can I fix the Certificate Verify Failed Error in Flutter?
In the mobile application sometimes when a user launches an app in the mobile application and then performs any activity Certificate Verify Failed error message appears at random. We shall thus walk through the same in this article.
The following Flutter unit test produces a dart:io HttpClient with a SecurityContext that is given with a Let’s Encrypt root certificate. The package:http IOClient, which implements the Client interface and can be used for all the common get, post, etc. operations, is then given this HttpClient.
1 2 3 4 5 6 7 |
I/flutter (10712): ApiUrl:------------>https://------.com/wp-json/wms/api/login I/flutter (10712): ApiAuthKey:--------> I/flutter (10712): ApiBodyData:------->{username: anjitrajput.qa630@webkul.com, password: Admin123, mFactor: 2.75, deviceToken: cWeBRbF9TbSgr6NuT1zHn2:APA91bF4YfyU4W4QnhS3DqtfaHHGnq8FE_bPaRjsyZMfEdlYwnkKuCaG07uDMlCmcsvY1QQ0MVo5rH4msFGvjHKX7B43hviEc3g36mtJTMC86eQRgIoJEG7F25_u2arHVYDiJWNQPMNQ, os: TargetPlatform.android} I/flutter (10712): ApiMethod:--------->POST I/flutter (27955): ApiError:---------->DioError [DioErrorType.other]: HandshakeException: Handshake error in client (OS Error: I/flutter (27955): CERTIFICATE_VERIFY_FAILED: certificate has expired(handshake.cc:393)) |
Read about the variety of Flutter App Development Services offered by Mobikul.
An HTTP client for communicating with an HTTP server. Sends HTTP requests to an HTTP server and receives responses. Maintains state, including session cookies and other cookies, between multiple requests to the same server. Note: HttpClient provides low-level HTTP functionality.
If you are facing the api calling issue please click here.
1 2 3 4 5 6 7 8 9 10 |
void main() { HttpOverrides.global = MyHttpOverrides(); runApp(Routes()); } class MyHttpOverrides extends HttpOverrides{ @override HttpClient createHttpClient(SecurityContext context){ return super.createHttpClient(context)..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;}} |
1 2 3 4 5 6 7 |
I/flutter (10712): ApiUrl:------------>https://----------.com/wp-json/wms/api/login I/flutter (10712): ApiAuthKey:--------> I/flutter (10712): ApiBodyData:------->{username: anjitrajput.qa630@webkul.com, password: Admin123, mFactor: 2.75, deviceToken: cWeBRbF9TbSgr6NuT1zHn2:APA91bF4YfyU4W4QnhS3DqtfaHHGnq8FE_bPaRjsyZMfEdlYwnkKuCaG07uDMlCmcsvY1QQ0MVo5rH4msFGvjHKX7B43hviEc3g36mtJTMC86eQRgIoJEG7F25_u2arHVYDiJWNQPMNQ, os: TargetPlatform.android} I/flutter (10712): ApiMethod:--------->POST I/flutter (10712): ApiStatusCode:----->200 [log] ApiResponse:------->{"id":6,"staffName":"anjilthakur","staffToken":6,"avatar":"https://secure.gravatar.com/avatar/e03ea0369912f57ac7365c7a11745064?s=96&d=mm&r=g","success":true,"message":"You have successfully logged in."} |
Certificate Verify Failed Error In Flutter generally comes with post api and below Android version 7. In Flutter, we can either supply Let’s Encrypt’s trusted certificate to dart:io HttpClient object (from the dart native communications library) via SecurityContext, which we can use to directly make https get/post calls, or we can supply that customised HttpClient to Flutter/Dart package:http IOClient if we are using that well-liked pub.dev package.
So in this article, we have been through how to solve the Flutter Certificate Verify Failed error while performing a POST request in Flutter.
Don’t forget to drop your valuable suggestions/feedback in the comments right below!!!
Thanks for reading this article. Send ❤️ if you like it.
For more understanding please can go through this Link
If you are facing any other issue related to the api calling and version please click here.
For more interesting blogs check here.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.