2012-03-23 45 views
0

你能幫我解決我的問題嗎?錯誤al conectar con localhost

我試圖訪問本地主機獲取從表中的數據,但我得到一個錯誤HttpHostConnectException當我運行它

完整的錯誤:org.apache.http.conn.HttpHostConnectException:連接到http://localhost拒絕

代碼使用:

public class MysqlConnectActivity extends Activity { 
private TextView tv; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    tv = (TextView) findViewById(R.id.TextView01); 
} 

private class DownloadPoints extends AsyncTask<String, Void, String> { 
    @Override 
    protected String doInBackground(String... urls) { 
     String response = ""; 

     try { 
      HttpClient client = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost("http://localhost/leerDatosUsuarios.php"); 
      HttpResponse execute = client.execute(httppost); 
      InputStream content = execute.getEntity().getContent(); 

      BufferedReader buffer = new BufferedReader(new InputStreamReader(content)); 
      String s = ""; 
      while ((s = buffer.readLine()) != null) { 
       response += s; 
      } 

     } 
     catch (Exception e) { 
      Log.e("log_tag", "Error en la conexion HTTP: "+e.toString()); 
     } 

     return response; 
    } 

    @Override 
    protected void onPostExecute(String result) { 
     tv.append("\nREAD FROM MYSQL:\n" + result); 
    } 
} 

public void readWebpage(View view) { 
    DownloadPoints task = new DownloadPoints(); 
    task.execute("http://localhost/leerDatosUsuarios.php"); 

} 

感謝您的關注 阿爾瓦羅

+0

有您的文章的英文版本? – Andreas 2012-03-23 13:45:26

回答

0

Localhost是您的實際Android設備。

如果您嘗試訪問開發計算機,則需要從模擬器訪問10.0.2.2。

+0

我不使用模擬器,我在我的android手機上運行。我試過192.168.1.4和10.0.2.2相同的錯誤:( – Alvaito 2012-03-23 16:32:52

+0

我使用mi ip地址(在MS2的ipconfig視圖中),我讀了「你沒有權限訪問此服務器上的/leerDatosUsuarios.php」然後, – Alvaito 2012-03-23 16:43:24

+0

可能是您的防火牆的問題 – njzk2 2012-03-23 17:03:37