0
I’m having a bit of a strange problem..
I need to return the status of some web addresses to the application, so I used the code below:
The algorithm, takes as a parameter a URL, then returns me the HTTP status. If so 200, I know you’re all right, if not, I’ll deal with it depending on the return.. Well, when I pass as parameters some specific sites it returns me the value 0 (Which is no HTTP status)
Could someone help me ?
Follow the code:
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;
}
Change your variable code to 3 and test with a site that was previously returning 0. Return works or becomes three?
– Lucas Torres
Hello Lucas, I changed. and the return became 3
– Alysson Chicó