'Flutter: Is it mandatory to selfSign server to call api in flutter with https

I have a spring boot server that doesn't have ssl certificate and NOT selfsigned. I want to call certain apis with https://domainName.com/apiPath . (with https:// not http://) So I found that I can set configs as to accept bad certificates. like this code...

import 'dart:io';

HttpClient client = new HttpClient();
client.badCertificateCallback =((X509Certificate cert, String  host, int port) => true);

io.HttpClientRequest request = await client.postUrl(Uri.parse(
    "https://domainname.com/apiPath"));
request.headers.set('Content-Type', 'application/json');

request.add(utf8.encode(jsonEncode(body)));
io.HttpClientResponse result = await request.close();

api call works with http://... But it doesn't work with https:// this is the error.

E/flutter ( 8183): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = <domain name>, port = 33028

Can I know, for this to work is it mandotory to self sign the backend(server)? (may be this is a stupid question. I don't know much about this topic)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source