【问题标题】:Xampp can't access htdocs when using local IPXampp 使用本地 IP 时无法访问 htdocs
【发布时间】:2016-11-26 21:55:40
【问题描述】:

我正在尝试让我的 android 应用程序访问我通过 lan 在我的 xampp 服务器上设置的 MySQL 数据库,但是当我使用我的电脑的本地 ip 时,我无法访问我的 htdocs 文件夹中的 PHP 脚本。我收到错误 404。我尝试使用邮递员访问它们,但发生了同样的事情,我收到错误 404。如果有帮助,这是我的 android 代码:

public class OrderingActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ordering);

    Log.d("lmao", "starting function");
    getItems();
}

RequestQueue requestQueue;
ArrayList<String> names;
ArrayList<Integer> prices;
String showUrl = "http://192.168.0.17:1234/phpmyadmin/upickss/showBar.php";

public void getItems(){

    Log.d("lmao","im alive");
requestQueue = Volley.newRequestQueue(getApplicationContext());
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,showUrl,null, new Response.Listener<JSONObject>(){
        @Override
        public void onResponse(JSONObject response) {
            try{
                Log.d("lmao", "trying");
                JSONArray drinks = response.getJSONArray("drinks");
                for (int i = 0; i < drinks.length();i++) {
                    JSONObject drink = drinks.getJSONObject(i);
                    String name = drink.getString("name");
                    names.add(i, name);
                    int price = drink.getInt("price");
                    prices.add(i, price);
                }
                Log.d("lmao",names.get(0));
            }catch(JSONException x){
                System.out.print(x);
            }
        }
    }, new Response.ErrorListener(){
        @Override
        public void onErrorResponse(VolleyError error){
            Log.d("lmao","error");

        }
    });
    requestQueue.add(jsonObjectRequest);

}

}

【问题讨论】:

    标签: android apache xampp


    【解决方案1】:

    这不是推荐的做法,因为您提供给应用程序的链接被认为是有害且无法访问的,因此 404 错误,我可以建议的唯一选择是将数据库托管在免费托管网站上,我们不会提供你的 404 错误。

    或者更确切地说,在模拟器上运行这个应用程序,用 10.0.2.2 替换 IP 地址,即 http://10.0.2.2/phpmyadmin/upickss/showBar.php

    在这种情况下,您可能还需要提供端口号

    http://10.0.2.2:[portno]/phpmyadmin/upickss/showBar.php

    【讨论】:

      猜你喜欢
      • 2013-12-27
      • 2014-09-05
      • 2012-07-20
      • 2018-08-23
      • 2012-10-10
      • 2018-03-05
      • 2021-04-07
      • 2013-11-27
      • 2013-09-08
      相关资源
      最近更新 更多