如何将网页的HTML内容作为字符串

时间:2015-03-10 17:40:37

标签: android http get server

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

2 个答案:

答案 0 :(得分:0)

使用以下方法

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";

此方法将值返回为字符串//20.5325117#-100.4038478

答案 1 :(得分:0)

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