我需要一点帮助来理解 Jsoup 的基础知识。以下代码有效,但我想知道是否需要以某种方式关闭连接。在 Jsoup 网站上找不到任何关于它的信息。如果在后台执行方法后应用程序保持不变,我每五分钟左右在 log cat 中收到一条消息,说“请求时间失败:java.net.SocketException:协议不支持地址族”。所以我想确保我没有不必要地消耗数据。谢谢你。
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try {
// connect to web page based on user input
Document doc = Jsoup.connect(routeURL).get();
// select relevant page elements
Elements fareStageNumbers = doc.getElementsByClass("fare_stages_inner_table");
// test printing out fare stage numbers
for(Element div : fareStageNumbers){
Log.v(TAG, div.text());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
日志信息:
01-12 20:58:28.755: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol
01-12 21:03:28.765: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol
01-12 21:08:28.775: D/SntpClient(78): request time failed: java.net.SocketException: Address family not supported by protocol