Hello
guys
I need output return nothing rather than Not Found . Still return ok it the url valid
How to get that don!!
Hello
guys
I need output return nothing rather than Not Found . Still return ok it the url valid
package javaUrl;
import java.net.HttpURLConnection;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
public class StrTest {
public static void main(String[] args) {
int i;
for(i= 0 ;i<=1000000;i++)
{
URLUtils.checkIfURLExists("http://xxxx"+i+".pdf");
System.out.println();
System.out.printf("%d ",i+1);
}
}
public static boolean checkIfURLExists(String targetUrl) {
HttpURLConnection httpUrlConn;
try {
httpUrlConn = (HttpURLConnection) new URL(targetUrl)
.openConnection();
httpUrlConn.setRequestMethod("HEAD");
httpUrlConn.setConnectTimeout(30000);
httpUrlConn.setReadTimeout(30000);
System.out.println("Response Message: "
+ httpUrlConn.getResponseMessage());
return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
return false;
}
}
}