I'm having a rather strange problem ..
I need to return the status of some web addresses for the application, so I used the code below:
The algorithm takes a URL as its parameter, so it returns me the HTTP status. If it's 200 , I know it's okay, if not , I'll handle it depending on the return .. Well, when I pass as a few specific site parameters it returns the value 0 (which is not an HTTP status)
Can anyone help me?
Follow the code below:
public static Integer verificarSistema(String enderecoUrl){
Integer code =0;
try {
URL url = new URL(enderecoUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
code = urlConnection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
in.close();
urlConnection.disconnect();
} catch (MalformedURLException e){
System.out.println("Erro ao criar URL. Formato inválido.");
} catch (IOException e2) {
}
return code;
}