How to post data to https server in dart?
http.post
is a convenience wrapper which creates a IOClient under the hood. You can pass your own io HttpClient to this, and that has a way to disable the certificate checks, so you just have to construct them yourself like this...
bool trustSelfSigned = true;
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => trustSelfSigned);
IOClient ioClient = new IOClient(httpClient);
ioClient.post(url, body:data);
// don't forget to call ioClient.close() when done
// note, this also closes the underlying HttpClient
the bool trustSelfSigned
controls whether you get the default behaviour or allows bad certificates.
best way for ssl certification problem on all http request
class MyHttpOverrides extends HttpOverrides{
@override
HttpClient createHttpClient(SecurityContext context){
return super.createHttpClient(context)
..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
}
}
void main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(new MyApp());
}