如何以字符串形式获取网页的 HTML 内容

How to get the HTML content of a webpage as a string

我正在尝试获取此网页 http://dbxserver.dbxprts.com:7778/pls/apex/training.d_respuesta?p_id_camion=1002 的 HTML 内容作为字符串并将其放入变量中我该怎么做?

使用以下方法

public String getJson(String url) throws ClientProtocolException,
            IOException {
        StringBuilder build = new StringBuilder();
        HttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                content));
        String con;
        while ((con = reader.readLine()) != null) {
            build.append(con);
        }
        return build.toString();
    }

备注

url = "http://dbxserver.dbxprts.com:7778/pls/apex/training.d_respuesta?p_id_camion=1002";

此方法return 值为字符串 //20.5325117 # -100.4038478

URL连接 读取数据到字符串... Reading from a URL Connection Java 或者,您可以使用 WebView 执行 Android 特定方法并覆盖 URL 加载(需要更长时间)。