简体   繁体   English

登录注册android app无法连接到本地服务器(连接被拒绝)

[英]Login register android app cant coonect to local server (connection refused)

This application registers users in a database. 该应用程序在数据库中注册用户。 When I click the register button, I get Connection Refused error in my logs. 单击注册按钮时,日志中Connection Refused error

My login and register localhost IP is : 127.0.0.1. 我的登录和注册localhost IP是:127.0.0.1。 I searched many websites and articles and they wrote >> you should change 127.0.0.1 to 10.0.2.2 but finally I didn't succeed. 我搜索了许多网站和文章,他们写了>>,您应该将127.0.0.1更改为10.0.2.2,但最终我没有成功。 My emulator is Nox player. 我的模拟器是Nox播放器。

    // Server user login url
public static String URL_LOGIN = "http://127.0.0.1:80/android_login_api/login.php";

// Server user register url
public static String URL_REGISTER = "http://127.0.0.1:80/android_login_api/register.php";

Well ! 好 ! Issue can be of the port you are referring to which is 80 in your case. 问题可能出在您所指的端口,在您的情况下为80 You can try changing the port to 8080 . 您可以尝试将端口更改为8080 In that case the Addresses may look like this: 在这种情况下,地址可能看起来像这样:

    // Server user login url
public static String URL_LOGIN = "http://127.0.0.1:8080/android_login_api/login.php";

// Server user register url
public static String URL_REGISTER = "http://127.0.0.1:8080/android_login_api/register.php";

Or try like this : 或者像这样尝试:

// Server user login url
public static String URL_LOGIN = "http://10.0.2.2:8080/android_login_api/login.php";

// Server user register url
public static String URL_REGISTER = "http://10.0.2.2:8080/android_login_api/register.php";

Double check: 再检查一遍:

  1. Your local host must be up and listening and you should be able to 您的本地主机必须启动并且正在监听,并且您应该能够
    hit the url in browser locally (if not then something is wrong with your local server) 在本地浏览器中点击网址(如果不是,则本地服务器出了点问题)
  2. Check INTERNET permission in your Manifest 检查清单中的INTERNET权限
  3. Port you are listening to must be open for connections. 您正在监听的Port必须open以进行连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM