【问题标题】:How to get the HTML content of a webpage as a string如何将网页的 HTML 内容作为字符串获取
【发布时间】:2015-03-10 17:40:37
【问题描述】:

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

【问题讨论】:

    标签: android http get server


    【解决方案1】:

    使用以下方法

    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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-12
        • 2014-07-26
        • 1970-01-01
        • 1970-01-01
        • 2016-01-31
        相关资源
        最近更新 更多