你能幫我解決我的問題嗎?錯誤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");
}
感謝您的關注 阿爾瓦羅
有您的文章的英文版本? – Andreas 2012-03-23 13:45:26