Ale*_*dis 5 basic-authentication superagent reactjs axios
我尝试使用axios发出GET请求,但总是得到401。只有当我从react应用发送请求时,才会发生这种情况。
axios.get('http://localhost:8080/vehicles', {
withCredentials: true,
auth: {
username: 'admin',
password: 'admin'
},
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
})
Run Code Online (Sandbox Code Playgroud)
具有相同凭据和基本身份验证集的邮递员GET请求有效。
如果我只是在浏览器中键入URL,就会出现一个登录框,并使用相同的凭据,它可以正常工作,我得到了想要的东西。
我也尝试过SuperAgent:
Request.get("http://localhost:8080/vehicles")
.withCredentials()
.auth('admin', 'admin')
.then(response => {
return response.body
});
Run Code Online (Sandbox Code Playgroud)
依然没有。
我看到了与此相关的问题,但没有人回答。
(基本身份验证:supergaent + OSX失败,superagent + Redhat上成功,Postman + OSX上成功,)
谁能指出我正确的方向?
感谢您的阅读。
| 归档时间: |
|
| 查看次数: |
1364 次 |
| 最近记录: |