如何使用模拟器从android ftp客户端连接本地主机?在“connect(host,port)”方法中应该使用什么ip和端口号?当我尝试使用端口号为21的10.0.2.2,127.0.0.1时,连接被拒绝。我正在使用Ubuntu和eclipse。 请帮忙......
答案 0 :(得分:0)
你应该像这段代码一样使用Asynctask:
@Override
protected ArrayList doInBackground(String ... params){ // TODO自动生成的方法存根
//activity is defined as a global variable in your AsyncTask
try {
HttpClient hc = new DefaultHttpClient();
HttpGet hg = new HttpGet(params[0]);
HttpResponse hr = hc.execute(hg);
HttpEntity he = hr.getEntity();
data = EntityUtils.toString(he);
Log.i("data", data);
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
然后当你像这样使用它时:
new asy().execute("http:// put your ip address here ");