Rashhh Rashhh - 1 year ago 181
Javascript Question

Unexpected end of JSON input error in Post request on api using access token in react-native

I am posting the details of user in api ,using the access token in header which i got in sign up but getting this error --> Unexpected end of JSON input. My code is


console.log("inside post api");
fetch('https://MyPostApi', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',

body: JSON.stringify({
gender: 'femanino',

}).then((response) => response.json())
.then((responseData) => {
console.log("inside responsejson");


Answer Source

This is because your response is not in json format. Space is missing between Bearer and your token, i think this will solve your issue.

'Authorization':'Bearer '+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'

Try your api call with postman first.