我正在尝试使用基本身份验证来获取托管在AWS上的php应用。我按照教程进行操作,并尝试了其他答案,例如使用btoa加密用户名和密码
当前,这是我的代码:
let h = new Headers();
let url = "URL"
let user = "USER"
let pass = "PASS"
let encoded = window.btoa(`${user}:${pass}` )
let auth = ('Basic ' + encoded)
console.log(auth)
h.append('Authorization', auth)
console.log(h.has('Authorization'))
fetch(url, {
headers: h
}) .then(res => console.log(res))
提前谢谢!