如何从URL获取数据? [英] How to get data from a URL?
问题描述
我在网站上提供了数据,如下图所示:
I have data provided in a website and it is presented as in the following image:
该网站提供了一些参数的值,这些参数会随时更新. 现在,我想根据Android应用程序中的列名和行号来检索这些数据,我知道如何打开http连接.但不幸的是,我不知道从哪里开始以及如何读取图像中提供的数据.
This website offers values of some parameters which are updated every while. Now I want to retrieve these data according to the column name and the row number in the Android app, I know how to open http connection. But unfortunately I have no idea from where should I start and how to read the data provided in the image.
推荐答案
除非您有特殊的数据源需要处理,否则您必须阅读网站的内容然后手动进行处理.这是 java教程中有关如何从URL连接读取的链接.
Unless you have a special data source to work on, you have to read the website's contents then process it manually. Here is a link from the java tutorials on how to read from an URL connection.
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
如果您位于代理之后,还应该将这些系统属性(设置为适当的值):
If you are behind a proxy you should also set these system properties (to the appropriate values):
System.setProperty("http.proxyHost", "3.182.12.1");
System.setProperty("http.proxyPort", "1111");
这篇关于如何从URL获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!