@GetMapping("/check")
public String checkURL(@RequestParam String url) {
String returnMessage = "";
try {
URL urlObj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
conn.connect();
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode() / 100;
conn.disconnect();
if (responseCode != 4 || responseCode != 3) {
returnMessage = siteStatus + " UP AND RUNNING";
} else {
returnMessage = siteStatus + " DOWN!";
}
} catch (MalformedURLException e) {
return siteStatus + " incorrect. Please try again.";
} catch (IOException e) {
returnMessage = e.getMessage();
}
return returnMessage;
}
This error is clearly due to IOException, if someone could help me fix this problem. I checked the URL is valid. I go to localhost:8080/check?url=https://www.example.com. I am pretty sure the syntax is correct. I even do conn.disconnect() to drop the connection yet I keep getting the error.