Reactjs Axios / Spring启动安全性

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

我有一个用Spring Boot开发的Java应用程序,它是后端的。前端是在ReactJs中开发的应用程序。我使用REST服务。我使用axios进行REST调用。我最近在Spring Boot中启用了安全性。现在我很难验证axios呼叫。

var config = {
        auth: {
            username: 'bruker',
            password: 'passord'
        }

    };
    axios.get('http://localhost:8090/employee/all', config).then(function (response) {
        console.log(response)
    }.bind(this)).catch(function (response) {
        console.log(response)
    }.bind(this))

我得到以下错误“预检的响应无效(重定向)”我假设响应被重定向到localhost:8090/login我没有找到任何解决方案。我做错了什么?

reactjs spring-security spring-boot axios
1个回答
0
投票

这篇文章现在已经很老了,但是我在这里遇到了类似的问题。在2018年。使用Axios如下让事情适合我:

    axios('/user', {
        method: 'POST',
        auth: {
            username: myUser,
            password: myPassword
        }
    }).then((response => {
        ...
    })).catch((error) => {
        ...
    })

请注意,区别在于用axios.get(...替换axios(...。将方法类型作为函数删除,并将其作为配置选项包含在内。它可能与axios导入的方式有关(import axios from 'axios'),但是一旦我的东西工作,我就没有深入研究。

希望有所帮助!

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