[英]Android Volley doesn't seem to be able to connect to Flask localhost address for GET method for return String from Flask?
[英]I wouldn't be able to connect to the Api Rest (made in python Flask Localhost) from my cell phone
嗨!你好嗎? 我想知道為什么我無法從手機連接到 Api Rest(在 python Flask Localhost 中制造)(我將它用作帶電纜的設備,我不使用模擬器)。 我不知道是否需要在 android 中配置一些東西。我在某處讀到你必須把它放在 AndroidManifest.xml 中
android:usesCleartextTraffic="true"
我把它放進去了,但它仍然不起作用。 我試過使用“localHost”“10.0.0.2”“http://127.0.0.1:8000/”但沒有任何效果。 我不知道我做錯了什么,我把我的代碼發給你
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];
}
}
如果你能幫助我,我將非常感激,我真的很想找到答案。
我對 flask 了解不多,但是:
ip addr
並在 Windows 上執行ipconfig
以獲得您的私有地址 IP。http.server
中,可能在 Flask 中,0.0.0.0 表示任何連接。 您也可以在此處查看我的類似問題。我找到了解決方案,在 Flask 你必須寫主機
if __name__ == '__main__':
# load_dotenv()
app.run(debug=True,port=8000,host="your Ip")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.