【发布时间】:2011-04-22 18:49:28
【问题描述】:
所以我使用的是另一篇较早的帖子中的以下代码,但有一部分有问题,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();
}
【问题讨论】:
-
对于 HttpGet 请求 = new HttpGet(www.stackoverflow.com);我将其更改为(“www.stackoverflow.com”);正如许多人所建议的那样,但其他行如“HttpResponse response = client.execute(request);”返回编译错误,都是:未处理的异常类型IOException,eclipse中的大部分快速修复建议“Surroned with try/catch”
标签: java android html syntax apache-commons-httpclient