我希望能够获取包含“true”或“false”单词的页面源代码。该页面上只有这两个单词,没有其他格式。
因此,我只需要使用Java连接到该页面“http://example.com/example.php”,并获取其内容。
因此,我只需要使用Java连接到该页面“http://example.com/example.php”,并获取其内容。
请尝试这个教程:Java URL示例 - 下载URL的内容
使用Apache Commons IO有一种简单的方法来实现这一点。例如,对于提到的操作,您只需编写:
URL url = new URL("http://example.com/example.php");
String content = IOUtils.toString(new InputStreamReader(
url.openStream()));