外層fetch獲取到了token,里面的fetch報錯,并且請求頭里面沒有傳輸的Authorization。let token;fetch('http://192.168.188.128:9080/user/login', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ username: 'zhangjh', password: 123, }),}).then(res => res.json()).then((json) => { token = json.token; fetch('http://192.168.188.128:9080/user/userid', { method: 'post', mode: 'no-cors', headers: { 'Content-Type': 'application/x-www-form-urlencoded', Authorization: token, }, }) .then(res => res.json()) .then((data) => { console.log(data); }) .catch(err => console.log(err)); }) .catch(err => console.log(err));
react使用fetch api獲取到了jwt返回的token然后帶上該token繼續請求報錯
慕桂英546537
2018-12-04 14:22:29