【发布时间】:2021-07-02 08:46:25
【问题描述】:
我正在尝试在浏览器上使用 fetch 但它不起作用。
我试过了:
fetch('https://api-2sizcg3ipa-uc.a.run.app/fats', {
headers: {'Authorization': 'Basic ' + btoa('username:password')},
mode:'no-cors'
})
.then(response => response.json())
.then(json => console.log(json));
但它给了我两个错误:
GET https://api-2sizcg3ipa-uc.a.run.app/fatsnet::ERR_ABORTED 403
Uncaught (in promise) SyntaxError: Unexpected end of input 在 fetch.js:5
我做错了什么?当我使用 curl 时,我会工作。
【问题讨论】:
标签: javascript json header cors fetch