2016-07-22 52 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