Pub: HandshakeException: Connection terminated during handshake

Created on 7 Apr 2019  路  7Comments  路  Source: dart-lang/pub

i tried to use an api on my localhost but when i run my app i got an error
*Unhandled Exception: HandshakeException: Connection terminated during handshake

here is my function where i got this error
Future> login(String email, String password) async {
Map userData = {'email': email, 'password': password};
_isLoading = true;
notifyListeners();
http.Response response = await http.post(Uri.encodeFull('https://10.0.2.2:8000/api/login'),
body: json.encode(userData),
headers: {'Content-Type': 'application/json'});

  print(json.decode(response.body));
  _isLoading = false;
  notifyListeners();
return userData;

}
}

Most helpful comment

call http://10.0.2.2:8000/api/login without s (secure) instead of https://10.0.2.2:8000/api/login
the HTTP is what what's making the handshake exception

All 7 comments

With code fencing.

Future<Map<String, dynamic>> login(String email, String password) async {
    Map<String, dynamic> userData = {'email': email, 'password': password};
    _isLoading = true;
    notifyListeners();
    http.Response response = await http.post(Uri.encodeFull('https://10.0.2.2:8000/api/login'),
        body: json.encode(userData),
        headers: {'Content-Type': 'application/json'});

      print(json.decode(response.body));
      _isLoading = false;
      notifyListeners();
    return userData;
  }
}

I'm not sure what you're trying to do?

What does this have to do with pub?

@jonasfj
i was trying to use api on my localhost but i got Connection terminated during handshake
and i don't know why this error

Use what API? Not sure what you're trying to achieve..

The error is probably a server accepting the TCP connections and then dropping it.. or something like that... Seems like a TCP thing.

Check your URL https://10.0.2.2:8000/api/login

https with port 8000 is most probably wrong ;)
Id try http://10.0.2.2:8000/api/login

call http://10.0.2.2:8000/api/login without s (secure) instead of https://10.0.2.2:8000/api/login
the HTTP is what what's making the handshake exception

This looks unrelated to pub and it looks like there is a suggested solution. I'll close this.

For future questions of this type stack overflow may be a better place to get help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSanford42 picture JSanford42  路  21Comments

wh120 picture wh120  路  24Comments

Andersmholmgren picture Andersmholmgren  路  45Comments

Scorpiion picture Scorpiion  路  24Comments

paulyoung picture paulyoung  路  21Comments