我一直在我的春季启动程序上获得此IOException错误消息。

发布于 2025-02-04 22:18:12 字数 1079 浏览 3 评论 0原文

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文