0

我有这个功能:

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 试过了)。可悲的是,结果总是空的。

谢谢帮助

4

1 回答 1

0

我的猜测(我只能根据您提供的信息猜测):

您忘记了清单中的 Internet 权限。

于 2012-09-10T16:22:13.190 回答