Reputation: 403
I have a flutter web app that connects to an HTTPS service that uses a self-signed certificate. I then added my certificate to my HTTP call as below:
String url = "$BASE_URL/authenticate/";
ByteData data = await rootBundle.load('assets/keystore.p12');
SecurityContext context = SecurityContext.defaultContext;
context.setTrustedCertificatesBytes(data.buffer.asUint8List(),
password: "password");
final httpClient = HttpClient(context: context);
final client = IOClient(httpClient);
final response = await client.post(Uri.parse(url),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(userObj));
However, I am getting the issue below:
Unsupported operation: default SecurityContext getter
Based on this, the issue is that I am using mqtt_server_client instead of mqtt_server_browser. How do I tell flutter to use the latter?
I also tried bypassing the bad certificate with the code below and got a different issue related to the usage of IOClient
httpClient.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
error:
Unsupported operation: Platform._version
Upvotes: 0
Views: 1736