Skip to content

Instantly share code, notes, and snippets.

@koral--
Last active March 2, 2023 23:27
Show Gist options
  • Save koral--/f39a621facc19946e1bc665e299033e1 to your computer and use it in GitHub Desktop.
Save koral--/f39a621facc19946e1bc665e299033e1 to your computer and use it in GitHub Desktop.
Dart HTTP client with certificate pinning
final securityContext = SecurityContext();
final certificates = await rootBundle.load('assets/certificates/google.crt'); //1
securityContext.setTrustedCertificatesBytes(certificates.buffer.asUint8List()); //2
final httpClient = HttpClient(context: securityContext);
final httpClientRequest = await httpClient.getUrl(Uri.parse('https://google.pl'));
final response = await httpClientRequest.close();
print(response.statusCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment