微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XAMPP 上的 PHP 代码可通过 Wifi 工作,但不能在 4g 下使用我的手机

如何解决XAMPP 上的 PHP 代码可通过 Wifi 工作,但不能在 4g 下使用我的手机

我已经完成了一个 android 应用程序来登录我的数据库并在我的 XAMPP 服务器上注册帐户。 此应用程序在我的 PC 和手机上运行良好,但仅当我处于 WiFi 连接下时。 当我切换到移动连接时(我的情况是 4g)在我的智能手机上不起作用。

系统捕捉到一个 IOException 并在一个对话框中写入我只配置了 PHP 文件的 url,例如“http://EXAMPLEIP/login.PHP”。

有人知道是不是配置问题? 不要介意EXAMPLEIP,在我的代码中有从ipconfig 命令获取的正确IP。

我使用 AsyncTask 处理连接:

@Override
protected String doInBackground(String... voids) {

    code = voids[0];
    username = voids[1];
    password = voids[2];

    if(code==LOGIN_CODE){
        web_address = "EXAMPLEIP/login.PHP";
    }else if(code==REGISTER_CODE){
        web_address = "EXAMPLEIP/register.PHP";
        bestPlace = voids[3];
    }

    try{
        URL url = new URL(web_address);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setRequestMethod("POST");
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(true);

        OutputStream outputStream = httpURLConnection.getoutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
        if(code==LOGIN_CODE){
            data = URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")
                    +"&&"+URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
        }else if(code==REGISTER_CODE){
            data = URLEncoder.encode("username","UTF-8")
                    +"&&"+URLEncoder.encode("bestPlace","UTF-8")+"="+URLEncoder.encode(bestPlace,"UTF-8");
        }
        writer.write(data);
        writer.flush();
        writer.close();
        outputStream.close();

        InputStream inputStream = httpURLConnection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"ISO-8859-1"));
        String line ="";
        while((line = reader.readLine())!=null){
            result += line;
        }
        reader.close();
        inputStream.close();
        httpURLConnection.disconnect();

        return result;

    }catch (MalformedURLException e){
        result = e.getMessage();
    }catch (IOException e){
        result = e.getMessage();
    }

    return result;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。