-1

Hi how are u? I wanted to know why I wouldn't be able to connect to the Api Rest (made in python Flask Localhost) from my cell phone (I use it as a divice with the cable, I don't use the emulator). I don't know if maybe something needs to be configured in android. I read somewhere that you have to put it in the AndroidManifest.xml

android:usesCleartextTraffic="true"

I put it in but it still doesn't work. I have tried using “localHost” “10.0.0.2” “http://127.0.0.1:8000/” but nothing works. I don't know what I'm doing wrong, I send you my code

class AuthService extends ChangeNotifier{
  final String _baseurl= 'http://10.0.2.2:8000';
  Future<String> login(String email, String password) async{
    final Map<String,dynamic> authData={
    'email':email,
    'password':password,
    // 'returnSecureToken':true
  };

  final url= Uri.http(_baseurl, 'api/auth'
  // {
  // 'key':_apiToken
  // }
  );

  final resp= await http.post(url,body:json.encode(authData));
  final Map<String,dynamic> decodeResp =json.decode(resp.body);
  print(resp);

  return decodeResp[0];

  }
}

If you can help me I would really appreciate it, I'm really going crazy trying to find the answer.

2 Answers2

0

I don't know much about flask, however:

  1. Are both devices on the same network? This may be a stupid question, but sometimes they aren't.
  2. Is the IP address you put the actual private IP address? You can do ip addr on Linux and ipconfig on Windows to get your private IP address.
  3. Try "0.0.0.0". In http.server, and possibly in Flask, 0.0.0.0 means any connection. You can also view my similar question here.
  • nothing works, its the same network, not even the private ip with write ifconfig the "wlp3s0" appears but when I try with another device it doesn't connect (which seems strange to me since I remember that before when I made a rest api I could connect through any computer from the same network by putting the private ip in the browser, but in this case it is not possible) – Emanuel Lemos Apr 17 '22 at 20:21
  • @EmanuelLemos Your private IP should be something like `10.0.1.1` or `192.168.1.1`, not "wlp3s0". Sorry I can't help much with Flask. There shouldn't be any different between a PC and a phone. Good luck! – MLG Herobrine Apr 18 '22 at 00:22
0

i find the solution , in Flask u must be to write the host

if __name__ == '__main__':
    # load_dotenv()
    app.run(debug=True,port=8000,host="your Ip")