【发布时间】:2015-03-10 17:40:37
【问题描述】:
我试图将此网页http://dbxserver.dbxprts.com:7778/pls/apex/training.d_respuesta?p_id_camion=1002 的 HTML 内容作为字符串并将其放入变量中,我该怎么做?
【问题讨论】:
我试图将此网页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";
此方法以字符串形式返回值 //20.5325117 # -100.4038478
【讨论】:
URL 连接 读取数据到字符串... Reading from a URL Connection Java 或者您可以使用 WebView 执行特定于 Android 的方法并覆盖 URL 加载(更长时间的工作)。
【讨论】: