private boolean canGetHtmlCode(String httpUrl) {
String htmlCode = "";try {
InputStream in;URL url = new java.net.URL(httpUrl);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection = (HttpURLConnection) url.openConnection();connection.setRequestProperty("User-Agent", "Mozilla/4.0");connection.connect();in = connection.getInputStream();byte[] buffer = new byte[50];in.read(buffer);htmlCode = new String(buffer);
} catch (Exception e) {}if (RmStringHelper.empty(htmlCode) || htmlCode.equals("")) {return false;}return true;
}
获取HTML代码的Java方法
本文介绍了一个使用Java实现的简单方法,该方法通过HTTP请求从指定URL获取HTML代码,并检查是否成功获取到有效的HTML内容。此方法利用了HttpURLConnection进行网络连接。
912

被折叠的 条评论
为什么被折叠?



