无法使用Axios或SuperAgent的React App进行基本身份验证

时间:2017-01-04 16:31:38

标签: reactjs basic-authentication axios superagent

我尝试使用axios发出GET请求,但我总是得到401.只有当我从反应应用程序发送请求时才会发生这种情况。

axios.get('http://localhost:8080/vehicles', {
        withCredentials: true,
        auth: {
            username: 'admin',
            password: 'admin'
        },
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
    })

具有相同凭据和基本身份验证设置的邮差GET请求有效。

如果我只是在我的浏览器中输入网址,就会出现一个登录框,并且使用相同的凭据,它可以工作,我得到了我想要的。

我也尝试过SuperAgent:

Request.get("http://localhost:8080/vehicles")
        .withCredentials()
        .auth('admin', 'admin')
        .then(response => {
            return response.body
        });

仍然没有。

我看到了一个与此相关的问题,但没有人回答。

Basic authentication : failure supergaent+OSX , success on superagent+Redhat , success on Postman+OSX,

有人能指出我正确的方向吗?

感谢您的阅读。

0 个答案:

没有答案
相关问题