如何解决404错误的XMLHttpRequest到本地主机

问题描述 投票:-1回答:1

我,而我试图发送POST请求的控制台上接收到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");

}

本地主机页的形式是:

<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(未找到)

问题是...当我用它工作网站的在线版本...但我想指出我的本地主机,所以我并不需要做的在线版本的变化。

javascript post request xmlhttprequest http-status-code-404
1个回答
2
投票

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

所以,当你发送该URL来https://cors-anywhere.herokuapp.com进行处理,该系统试图访问https://cors-anywhere.herokuapp.com/something,因为localhost点到其服务器,以及资源无法找到。

不要使用代理服务器或改为发送your真正IP address localhost来解决这个问题!

© www.soinside.com 2019 - 2024. All rights reserved.