2016-07-22 84 views
-1

我试图让我的android应用程序访问MySQL数据库我已经通过局域网在我的xampp服务器上进行了设置,但是当我使用我的电脑本地IP时,我无法访问我的htdocs文件夹上的PHP脚本。我得到404.我试图与邮差访问它们,同样的事情发生了一个错误,我得到一个错误404。这是我的Android代码,如果它的任何帮助:Xampp使用本地IP时无法访问htdocs

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); 

} 

}

回答

0

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

或者说运行在模拟器这个应用程序替换10.0.2.2即 http://10.0.2.2/phpmyadmin/upickss/showBar.php

的IP地址,您可能还需要提供无端口,在这种情况下

http://10.0.2.2:[port无]/phpMyAdmin的/ upickss/showBar.php