0

I am trying to validate all the broken links in a page but I'm getting the "Connection refused: connect" message. Below is the code that I have used. I am using chrome driver.

public static void verifyLink(String linkUrl) throws IOException {

        URL url = new URL(linkUrl);
        HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection();
        httpURLConnect.setConnectTimeout(3000);
        httpURLConnect.connect();

        if(httpURLConnect.getResponseCode()==200) {
            System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage());
         }

       if(httpURLConnect.getResponseCode()==HttpURLConnection.HTTP_NOT_FOUND) {
            System.out.println(linkUrl+" - "+httpURLConnect.getResponseMessage() + " - "+ HttpURLConnection.HTTP_NOT_FOUND);
         }

    }

Please help me.

Gokul
  • 788
  • 2
  • 12
  • 30
Arijit Biswas
  • 81
  • 1
  • 3
  • 16

1 Answers1

0

Try to increase timeout httpURLConnect.setConnectTimeout(3000); from 3 seconds to 5.
Or the second option, maybe you need to set some cooldown, because server start think that you're making DDoS attack.
Try to add timeout. For example implicit wait.

Grynets
  • 2,477
  • 1
  • 17
  • 41
  • I executed by increasing the timeout to 10 seconds but did not work. Any other wayout for this issue? – Arijit Biswas Oct 25 '17 at 08:08
  • @ArijitBiswas, as I said, the second option is to make timeout between your calls. I don't know how exactly you need to do this in Java, but this post https://stackoverflow.com/a/26311872/6066986 may be helpful for you – Grynets Oct 25 '17 at 10:31