New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https over self-signed certificate #32
Comments
You should create a dio.onHttpClientCreate = (HttpClient client) {
// create a `SecurityContext` instance to trust you certificate
return HttpClient(securityContext)
}; More about |
Consider adding support for badCertificateCallback.
perhaps as an option to the constructor:
|
it doesn't seem like onHttpClientCreate() is ever reached: Dio dio = new Dio();
dio.onHttpClientCreate = (HttpClient client) {
print('onHttpClientCreate entered...'); // this code is never reached
client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
return client;
};
Response<String> response=await dio.get(url); //CERTIFICATE_VERIFY_FAILED:ok |
Are you sure? I have run the code as follows: dio.onHttpClientCreate = (HttpClient client) {
print("dio xxxx");
client.badCertificateCallback =
(X509Certificate cert, String host, int port) {
return true;
};
}; Console log
Which version of dio do you use? 0.1.3? |
Yes, It never ran on my box. I've submitted a pull request to support self-signed certs. Please consider. This works. Great plugin btw!! |
@wendux I created a new project and was able to confirm dio.onHttpClientCreate() ran successfully. Using version 0.1.3 |
@pepie Ok, May you overwrite |
I'm guessing that's the case. |
what about this issuse ? |
Closing this issue since a solution was found. void main(){ |
|
Dio dio = new Dio(); |
DioForNative dio = DioForNative(); |
Based on this cfug/dio#32 (comment)
How to disable SSL certificate check using Dio in WEB ENVIRONMENT? |
This is not SAFE for production versions! We need other reply to resolve it, anyone? |
@bambinoua Have you found a solution for flutter web? |
In my case I needed to use an self signed certificate and the solution was this:
|
Actual on March 2024:
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
Dio createDio({required String baseUrl, bool trustSelfSigned = false}) {
// initialize dio
final dio = Dio()
..options.baseUrl = baseUrl;
// allow self-signed certificate
(dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () {
final client = HttpClient();
client.badCertificateCallback = (cert, host, port) => trustSelfSigned;
return client;
};
return dio;
} |
'CERTIFICATE_VERIFY_FAILED' exception is thrown, when connection to server with self-signed certificate.
The text was updated successfully, but these errors were encountered: