Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I am new in flutter, this is my code to connect to an API REST
 final String _baseUrl = 'https://localhost:7254/api/login/getTokenLogin';
 final Map<String, dynamic> authData = {
      'email': email,
      'password': password
    };

final url = Uri.parse(_baseUrl); //  , 
final resp = await http.post(url, body: json.encode(authData));


Using POSTMAN and SWAGGER it works perfect, but using the code above i got this message:
_ClientSocketException (Connection refused)


Any help?
Thanks

What I have tried:

I Had checked privilegies, Other codes in flutter, the _baseUrl in Postman and Swagger
Posted
Updated 27-Jan-23 5:02am

1 solution

I found this soluction and its WORKS for me:
class PostHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

void main() {
  HttpOverrides.global = PostHttpOverrides();
  runApp(AppState());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900