Java,验证响应代码URL
这是代码:Java,验证响应代码URL,java,url,Java,Url,这是代码: public class Main { public static void main(String[] argv) throws Exception { URL url = new URI("http://www.google.com").toURL(); URLConnection conn = url.openConnection(); Reader rd = new InputStreamReader(conn.getInputStream())
public class Main {
public static void main(String[] argv) throws Exception
{
URL url = new URI("http://www.google.com").toURL();
URLConnection conn = url.openConnection();
Reader rd = new InputStreamReader(conn.getInputStream());
EditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
kit.read(rd, doc, 0);
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
String link = (String) s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
System.out.println(link);
}
it.next();
}
}
}
问题:
如何做到这一点……google.com中包含的每个页面都要检查getResponseCode
例如:
-响应代码200
-响应代码407
。。。。。。。。。
这个小程序将生成一个google.com页面。如何使生成的每个页面都显示ResponseCode答案?我想在每一面分别检查注释,只有一个代码检查所有注释。
我可以使用loop?只要调用,呃,在你得到输入流之前,你会相信
urlconnection.getResponseCode(),
。我一个字也不懂。再试一次。这个小程序将生成一个google.com页面。如何使生成的每个页面显示ResponseCode答案?我不想单独检查每一面的代码,只想检查其中的一个代码。