2013-04-15 91 views
1

我已經寫在我連接使用通過仿真系統的IP地址到本地主機的應用程序,但現在我想通過Android設備連接通過Android設備的本地主機

問題是連接到本地主機每當我試圖通過應用程序連接得到一個問題,總之:本地主機不響應.....

我使用WiFi進行連接本地主機..任何幫助,請....

代碼:

public void onClick(View v) { 

       String url = "http://ipaddress/checkLogin.php"; 
       List<NameValuePair> params = new ArrayList<NameValuePair>(); 
       params.add(new BasicNameValuePair("strUser", txtUser.getText().toString())); 
       params.add(new BasicNameValuePair("strPass", txtPass.getText().toString())); 
       String resultServer = getHttpPost(url,params); 
       Log.d("Entire string::", " "+resultServer); 
+0

http://www.mobitechie.com/android-2/how-to-access-localhost -on-android-over-wifi/ –

回答

2

不要使用WiFi通過Android設備連接,一定要使用通過USB設備連接本地主機或將您的文件,並使用在線服務器使數據庫...

並沒有錯,你的代碼:

public void onClick(View v) { 

      String url = "http://ipaddress/checkLogin.php"; 
      List<NameValuePair> params = new ArrayList<NameValuePair>(); 
      params.add(new BasicNameValuePair("strUser", txtUser.getText().toString())); 
      params.add(new BasicNameValuePair("strPass", txtPass.getText().toString())); 
      String resultServer = getHttpPost(url,params); 
      Log.d("Entire string::", " "+resultServer); 
+0

歡迎來到SO並感謝幫助,我想你也可以在這裏幫助我:http://stackoverflow.com/questions/15984338/how-to-update-quantity-using-tap -on-item-in-a-listview –

+0

-1長期濫用單詞「localhost」來引用客戶機軟件本身運行的機器(真實或模擬的)以外的任何東西。 –

+0

試試這個:http://stackoverflow.com/a/17603378/1600061 –

1

USB不爲移動設備提供網絡。如果它連接到你的wifi,然後打你的路由器提供的筆記本電腦地址。如果它連接到您的移動網絡,那麼首先找出您的路由器外部IP地址,然後將某個端口轉發到10.0.2.2:portno,最後您將能夠從您的設備中看到該服務器。

C:\ WAMP \ BIN \ apache的\ Apache2.2.11 \的conf \ httpd.conf中

onlineoffline tag - don't remove 
    Order Deny,Allow 
    Allow from all // change it Allow 
    Allow from 127.0.0.1 
+2

10.0.2.2只適用於模擬器,它不適用於物理設備。 –

+0

Chris在設備上做什麼? – Lion789

相關問題