我一直在我的春季启动程序上获得此IOException错误消息。
@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;
}
如果有人可以帮助我解决此问题,则此错误显然是由于IOException所致。我检查了URL有效。我转到Localhost:8080/check?url = https://www.example.com。我很确定语法是正确的。我什至做conn.disconnect()以删除连接,但我一直遇到错误。
@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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论