【问题标题】:[ANDROID]How to get HTML source from a URL(using WEBAPI for uTorrent)[ANDROID]如何从 URL 中获取 HTML 源代码(使用 WEBAPI for uTorrent)
【发布时间】:2016-10-26 08:01:37
【问题描述】:

我需要从 url 中的 HTML 代码中获取一个简单的字符串。

FwyKvZJSZMLdgAlEuMvw7v_s9VhasprI-47KeavMegGJlvAC5ZLwng5gEFgAAAAA .

这就是它的样子。我需要的只是从一开始的字符串。

这是我用来访问代码的 URL 请求。

http://username:password@IP:8080/gui/token.html

我找到的答案要么太复杂,要么直接不起作用(HTTPClient 现在已弃用:()。

这就是我所拥有的,但遗憾的是它总是返回 java.io.FileNotFoundException: http://www.google.com 并且它在每个网站上都会这样做。

这是它的代码:

try {
    System.out.println("TEST");
    con = (HttpURLConnection) new URL("http://username:password@IP:8080/gui/token.html").openConnection();
    con.setRequestMethod("GET");
    con.setDoOutput(true);
    con.setDoInput(true);
    System.out.println(con.getOutputStream().toString());
    InputStream response = con.getInputStream();
    System.out.println("RMessage" + con.getResponseMessage());
    con.setRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) ");
    con.setRequestProperty("Accept","*/*");
    BufferedReader reader = new BufferedReader(new InputStreamReader(response));
    for (String line; (line = reader.readLine()) != null; ) {
        System.out.println(line + "NEKAJ SE JE ZGODILO V PRIDOBITVI");
    }
    reader.close();

} catch (MalformedURLException e1) {
    e1.printStackTrace();
} catch (ProtocolException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}

}

该链接在我设备上的 Chrome 应用中可以正常使用。

获取 Facebook.com 或 Google 之类的资源也可以。我很困惑。

编辑:打印堆栈跟踪: 10-26 11:45:52.816 3341-3721/com.example.davidvuckovic7.utorrentclient W/System.err: java.io.FileNotFoundException:

为避免为其发布单独的帖子,有没有办法自定义 URL?获取用户输入的用户名和密码还是用户输入的IP?

【问题讨论】:

    标签: android html url token utorrent


    【解决方案1】:

    显然我需要修复我的 cookie。因为浏览器会自动处理 cookie 而我的应用程序不会,所以会导致问题。令牌和 cookie 显然是相互关联的。

    现在开始下一个问题,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 2014-07-25
      • 2012-08-19
      相关资源
      最近更新 更多