0

我想制作一个应用程序供我自己使用。要显示 wimax 信号、CINR、上传速度等。当设备连接时,打开浏览器 http://192.168.2.1,登录后(javascript 登录页面)会显示值。

我想将这些数据传输到我的应用程序中。那么,我该怎么做呢?有什么例子吗?

信息的图像

4

1 回答 1

1

您可以使用 Jsoup 之类的库来解析 HTML 数据。

我假设这是您尝试访问的路由器,它通常使用基本身份验证。您还需要一个库来为基本身份验证执行 base64 编码,例如 Apache commons。

import org.apache.commons.codec.binary.Base64;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

...

public static void main(String[] args) {

    String username = "username";
    String password = "password";
    String login = username + ":" + password;
    String base64login = new String(Base64.encodeBase64(login.getBytes()));

    Document document = Jsoup
        .connect("http://192.168.2.1")
        .header("Authorization", "Basic " + base64login)
        .get();

    Element e = document.select("body");
    ...
    /* Select the elements and HTML text you're interested here */
}

这应该足以让你开始。您可以在此处了解有关如何使用 Jsoup 的更多信息

于 2016-05-22T20:47:32.063 回答