在 react-native 中使用访问令牌 api 上的 Post 请求中 JSON 的意外输入错误
Unexpected end of JSON input error in Post request on api using access token in react-native
我在 api 中发布用户的详细信息,使用我在注册时获得的 header 中的访问令牌,但收到此错误 --> JSON 的意外结束输入。我的密码是
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();
}
这是因为您的回复不是 json 格式。 Bearer 和您的令牌之间缺少 Space,我认为这会解决您的问题。
'Authorization':'Bearer '+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'
先尝试与 postman 进行 api 通话。
我在 api 中发布用户的详细信息,使用我在注册时获得的 header 中的访问令牌,但收到此错误 --> JSON 的意外结束输入。我的密码是
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();
}
这是因为您的回复不是 json 格式。 Bearer 和您的令牌之间缺少 Space,我认为这会解决您的问题。
'Authorization':'Bearer '+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'
先尝试与 postman 进行 api 通话。