0
我有這樣的功能:這個get-HTML-from-Url-Function中的錯誤在哪裏?
public String getUrl(String url) {
HttpClient httpclient = new DefaultHttpClient();
String html = "";
try {
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet(url);
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);
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();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
return html;
}
}
的問題是,這些功能不會返回任何字符(我和google.de嘗試了一下)。可悲的是,結果總是空的。
THX的幫助
任何stacktrace可能? – njzk2