Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React Js Axios Post请求未从web api接收正文_Javascript_Reactjs_Axios - Fatal编程技术网

Javascript React Js Axios Post请求未从web api接收正文

Javascript React Js Axios Post请求未从web api接收正文,javascript,reactjs,axios,Javascript,Reactjs,Axios,所以我有一个web api,它可以生成一个令牌,当你给它发送一个用户名和密码时返回,如果你给一个像这样的尸体,它可以通过邮递员工作 这是可行的,它会给你一个令牌和正确的信息,但当我在chrome、firefox或ie上这样做时,它会给我一个错误,我的代码是这样的 var d = { username: Uname, surname: Pword, grant_type: "password", client_id: "099153

所以我有一个web api,它可以生成一个令牌,当你给它发送一个用户名和密码时返回,如果你给一个像这样的尸体,它可以通过邮递员工作

这是可行的,它会给你一个令牌和正确的信息,但当我在chrome、firefox或ie上这样做时,它会给我一个错误,我的代码是这样的

var d = {
        username: Uname,
        surname: Pword,
        grant_type: "password",
        client_id: "099153c2625149bc8ecb3e85e03f0022",
    };
    console.log(d);

    var self = this;
    return (
        axios.post('http://localhost/hydraauth/oauth/token', {
            headers: {
                'Content-Type': 'application/json',
            },
            data: d
        }).then(function (response) {
            console.log(response.data)
            self.setState({
                isLoggedIn: true,
                Uname: Uname,
            }, function () {
                sessionStorage.setItem("Login", true);
                sessionStorage.setItem("Uname", Uname)
                window.location.href = "/";
            });
        }).catch(function (error) {
            if (error.response){
            console.log(error.response)
            console.log(error.response.data);
            console.log(error.response.status);
            console.log(error.response.headers);
            } else {
            window.alert("Incorrect Username Or Password Or Unauthorized To Access This.")
            }
        })
    );
这让我在chrome中出现了这个错误

下面是错误扩展

响应选项卡中网络选项卡的图像为空


Axios存在通过body发送数据的问题,因此您需要使用

像这样使用它

axios.post("http://localhost/hydraauth/oauth/token", querystring.stringify({ "username": Uname, "password": Pword, "grant_type": "password", "client_id": "eyJjbGllbnRfaWQiOiJTYXZ2eS1Dcm0tUmVhY3QtSnMtU3lzdGVtIn0" }))

我猜问题是因为@BardiaRastin,当它从PostMan开始工作时,它怎么可能是cors,因为cors只存在于浏览器中…cors错误在哪里呢?因为在我的web api中,它是用corstake设置的。开发者工具中的“查看网络”选项卡也可以查看和