因此,我使用的是另一篇较早的帖子中的以下代码,但是其中一个部分遇到了问题,即:行HttpGet request = new HttpGet(url);
不起作用。在 url 位置我放了类似的东西www.stackoverflow.com
,但是那一部分不会让代码编译。我基本上是在尝试从 html 网站提取文本。完整代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(www.stackoverflow.com);
HttpResponse response = client.execute(request);
String html = "Toronto-GTA";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
}