0

我需要从 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?

4

1 回答 1

0

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

现在进入下一个问题,

于 2016-10-26T15:17:59.050 回答