你能帮我解决我的问题吗?错误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