I am new to flutter development. I am trying hard to make the https calls work. Whenever I call a https URL, it throws the below error:
SocketException: Failed host lookup: 'someserver.com' (OS Error: nodename nor servname provided, or not known, errno = 8)
Below is the code I am using:
final ioc = new HttpClient(); ioc.badCertificateCallback = (X509Certificate cert, String host, int port) => true; final http = new IOClient(ioc); return http .post(url, body: body, headers: headers, encoding: encoding) .then((response) { final String res = response.body; final int statusCode = response.statusCode; if (statusCode < 200 || statusCode > 400 || json == null) { throw new Exception("Error while posting data"); } return _decoder.convert(res); });
I have checked below few links and many more and tried all of them but nothing seems to work.
- How to solve SocketException: Failed host lookup: 'www.xyz.com' (OS Error: No address associated with hostname, errno = 7)
- https://github.com/flutter/flutter/issues/27883
Also please note that I am able to access the server from the browser. Same server is being access from iOS app as well(built using XCode). From iOS I am able to access the server.
Kindly help!