我張貼用戶在api中的詳細信息,使用標題中的訪問令牌,我得到了註冊但獲取此錯誤 - > JSON輸入意外結束。我的代碼是意外結束JSON輸入錯誤中使用訪問令牌在反應原生API在發佈請求
postNameToApi()
{
console.log("inside post api");
fetch('https://MyPostApi', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization':'Bearer'+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'
},
body: JSON.stringify({
dob:'1992-04-18',
gender: 'femanino',
is_professional:true,
is_referee:false
})
}).then((response) => response.json())
.then((responseData) => {
console.log("inside responsejson");
console.log('response:',responseData);
//this.setState({response:responseData});
}).done();
}
您是否檢查響應是否可以(或403)?你有沒有檢查響應主體是否是JSON?你的開發工具的網絡面板對響應有什麼評論? – Bergi
是的,我做到了。 @Bergi –