Created
March 2, 2023 23:44
-
-
Save koral--/48492d00452c9e8df2c38f2eb5fd28b5 to your computer and use it in GitHub Desktop.
Dio with HTTP certificates pinning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final certificates = await rootBundle.load('assets/openssl/google.crt'); | |
final dio = Dio(); | |
(dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate = (client) { | |
final securityContext = SecurityContext(); //1 | |
securityContext.setTrustedCertificatesBytes(certificates.buffer.asUint8List()); | |
return HttpClient(context: securityContext); | |
}; | |
final response = await dio.getUri(Uri.parse('https://google.pl')); | |
print(response.statusCode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment