如何进行从React Axios GET调用到SpringBoot微服务的基本身份验证

时间:2019-01-09 18:33:44

标签: reactjs spring-boot axios microservices

Postman Request Details enter image description here 我正在使用axios.get()调用安全的SpringBoot微服务,但它返回401未经授权的响应。 邮递员返回了SpringBoot微服务的预期输出,但未返回React App

我尝试了互联网上所有可用的方法,但徒劳无功。

请帮助我解决此问题。

React Call:将auth作为参数传递,因为它是在Axios中进行基本身份验证的方式

    axios.get('http://localhost:8080/hellouser/greet/',
     {},
    {auth:{
        username:'demouser',
        password:'demopassword'
        }}).then(function (response) {
console.log(response);
  })

1 个答案:

答案 0 :(得分:0)

改为尝试这种方法

axios.get('http://localhost:8080/hellouser/greet/', {
    params: {},
    withCredentials: true,
    auth: {
        username: 'myusername',
        password: 'mypassword'
    }
})

您可能还会检查库的版本。可能一个到另一个