我有这个功能:
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 试过了)。可悲的是,结果总是空的。
谢谢帮助