下面是我的代码。我的应用程序网址适用于HTTPS和代理。这段代码有什么问题?
对于所有网址,我都会显示错误。
public void brokenLink() throws IOException {
List<WebElement> urllinks = driver.findElements(By.tagName("a"));
for (int i = 0; i < urllinks.size(); i++) {
WebElement urllink = urllinks.get(i);
String link = urllink.getAttribute("href");
verifylinkActive(link);
}
}
private void verifylinkActive(String link) throws IOException {
try {
System.out.println(link);
// TODO Auto-generated method stub
URL activelinks = new URL(link);
System.setProperty("https.proxyHost", "proxy.abc.com");
System.setProperty("https.proxyPort", "8080");
HttpURLConnection httpUrlConnect = (HttpURLConnection) activelinks.openConnection();
httpUrlConnect.usingProxy();
httpUrlConnect.setConnectTimeout(3000);
httpUrlConnect.connect();
System.out.println(httpUrlConnect.getResponseCode());
if (httpUrlConnect.getResponseCode() == 200) {
System.out.println(link + "-" + httpUrlConnect.getResponseMessage());
}
if (httpUrlConnect.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
System.out.println(
link + "-" + httpUrlConnect.getResponseMessage() + "-" + HttpURLConnection.HTTP_NOT_FOUND);
}
} catch (Exception e) {
System.out.println("Error");
}
}