【问题标题】:How to fix 404 error XMLHttpRequest to a localhost如何将 404 错误 XMLHttpRequest 修复到本地主机
【发布时间】:2019-06-30 15:42:11
【问题描述】:

我在尝试发送发布请求时在控制台上收到 404 错误。

我将https://cors-anywhere.herokuapp.com/ 用作代理,因此我可以在本地主机上解决任何跨域问题。

我的代码是:

function test() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
    alert(this.readyState + " // " + this.status);
}
xhttp.open("POST", "https://cors-anywhere.herokuapp.com/http://localhost/safecom/webuser.dll/Welcome", true);
xhttp.send("flogon=test&fpwd=123456");

}

localhost页面形式为:

<form method="post" enctype="application/x-www-form-urlencoded" name="loginForm" id="loginForm" action="Welcome">
<input type="hidden" name="redirpage" value="">
<input type="hidden" name="redirparam" id="redirparam" value="">
<input type="hidden" name="flogontext" value="User logon">
<input type="hidden" name="fpwdtext" value="PIN code">
<input type="hidden" name="flogonEnc" id="flogonEnc" value="">
<div class="login_form_element">
    <div class="login_field_user_box_border">
        <div class="login_field_user_box">
            <div class="logon_field_lbl" id="lblUserLogon" onclick="field_focus(flogon)">User logon</div>
            <input class="login_field_input" type="text" name="flogon" id="flogon" maxlength="254" size="24" value="">
        </div>
    </div>
</div>
<div class="login_form_element">
    <div class="login_field_user_box_border">
        <div class="logon_field_lbl_pwd" id="lblPassword" onclick="field_focus(fpwd)">PIN code</div>
        <input class="login_field_password_input" type="password" name="fpwd" id="fpwd" maxlength="4" value="">
    </div>
</div>
<div class="login_form_element">
    <input id="btnloginsubmit" class="rounded_login_btn" type="submit" value="Login"></div>

Chrome 控制台将错误指向我发送()的行,说: 加载资源失败:服务器响应状态为 404(未找到)

问题是......当我使用网站的在线版本时,它可以工作......但我想指向我的本地主机,所以我不需要对在线版本进行更改。

【问题讨论】:

  • 我不认为 localhost 会起作用,因为它的名字暗示只有本地。 heroku 应用程序不知道 localhost 是什么。尝试传递您的公共 IP 地址。
  • 无法使用公共 IP 地址
  • 您是否使用 Apache 或 nginx 之类的东西托管页面?如果没有,那根本行不通

标签: javascript post request xmlhttprequest http-status-code-404


【解决方案1】:

http://localhost 是“我的电脑”的符号。

因此,当您将此 URL 发送到 https://cors-anywhere.herokuapp.com 进行处理时,系统会尝试访问 https://cors-anywhere.herokuapp.com/something,因为 localhost 指向其服务器,并且找不到该资源。

不要使用代理或发送your真正的IP address而不是localhost来解决这个问题!

【讨论】:

    猜你喜欢
    • 2013-08-14
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2017-02-05
    • 2018-06-28
    • 2013-07-22
    相关资源
    最近更新 更多