我想下載一個網站的源代碼,並在文本框中顯示,但我似乎得到一個錯誤,無法弄明白:■下載html源碼android?
public void getHtml() throws ClientProtocolException, IOException
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://www.spartanjava.com");
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()
)
);
String line = null;
while ((line = reader.readLine()) != null){
result += line + "\n";
Toast.makeText(activity.this, line.toString(), Toast.LENGTH_LONG).show();
}
}
怎麼來的,這並不工作,並拋出IOException?
...其中它拋出異常 - 你可以標記的代碼行,請和發佈錯誤消息? – 2010-06-18 07:23:56
HttpResponse response = httpClient.execute(httpGet,localContext); 這就是拋出異常,但Levara的評論固定它:D這是一個許可的事情 – Mars 2010-06-18 09:02:48