【问题标题】:Redirect a html file to the localhost on port 8080将 html 文件重定向到 localhost 的 8080 端口
【发布时间】:2025-12-21 10:55:06
【问题描述】:

我有一个使用 okta web api 的简单网页:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous" />
        <title>Simple Web Page</title>
        <style>
            h1 {
                margin: 2em 0;
            }
        </style>
        <!-- widget stuff here -->
        <script src="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.16.0/js/okta-sign-in.min.js" type="text/javascript"></script>
        <link href="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.16.0/css/okta-sign-in.min.css" type="text/css" rel="stylesheet" />
        <link href="https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.16.0/css/okta-theme.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <div class="container">
            <h1 class="text-center">Test</h1>
            <div id="messageBox" class="jumbotron">
                You are not logged in. 
            </div>
            <!-- where the sign-in form will be displayed -->
            <div id="okta-login-container"></div>
        </div>
        <script type="text/javascript">
            var oktaSignIn = new OktaSignIn({
                baseUrl: "{{ https://dev-8490637.okta.com }}",
                clientId: "{{ 0oa97ptccRHXCE3kN5d5 }}",
                authParams: {
                    issuer: "default",
                    responseType: ["token", "id_token"],
                    display: "page",
                },
            });

            if (oktaSignIn.token.hasTokensInUrl()) {
                oktaSignIn.token.parseTokensFromUrl(
                    // If we get here, the user just logged in.
                    function success(res) {
                        var accessToken = res[0];
                        var idToken = res[1];

                        oktaSignIn.tokenManager.add("accessToken", accessToken);
                        oktaSignIn.tokenManager.add("idToken", idToken);

                        window.location.hash = "";
                        document.getElementById("messageBox").innerHTML = "Hello, " + idToken.claims.email + "! You just logged in! :)";
                    },
                    function error(err) {
                        console.error(err);
                    }
                );
            } else {
                oktaSignIn.session.get(function (res) {
                    // If we get here, the user is already signed in.
                    if (res.status === "ACTIVE") {
                        document.getElementById("messageBox").innerHTML = "Hello, " + res.login + "! You are *still* logged in! :)";
                        return;
                    }
                    oktaSignIn.renderEl(
                        { el: "#okta-login-container" },
                        function success(res) {},
                        function error(err) {
                            console.error(err);
                        }
                    );
                });
            }
        </script>
    </body>
</html>

我的笔记本电脑上安装了 python。

当我打开包含我的 index.html 文件的 Visual Studio 代码终端时,我使用以下命令:

cd C:\Users\marta\test (directory where my code is)
python -m http.server 8080 (redirect to port 8080)

我检查了我的防火墙/防病毒软件是否允许谷歌运行并且它是正确的。 问题:当我加载 http://localhost:8080/ 时继续显示这个错误:

【问题讨论】:

标签: html visual-studio-code localhost


【解决方案1】:

首先,您可能需要验证端口 8080 是否打开

telnet 127.0.0.1 8080

如果不是 Trying,那么它是打开的。 Ctrl+C 断开此连接 如果显示没有 telnet 命令,请尝试在 Windows 组件中安装 telnet-client。

【讨论】:

    【解决方案2】:

    您可以先验证桌面上的端口是否打开。如果没有打开,通常 HTML 文件不需要 localhost。它们可以从文件所在的文件管理器中打开。不过,您可以检查 localhost 是否打开:

    telnet 127.0.0.1 8080
    

    localhost:8080 
    

    可以进入浏览器查看。

    【讨论】:

      最近更新 更多