I hope someone here can help shred some light on the issue for me. I have been fighting this one error for too long now.
I am making a fetch request to an API for a sensor, which results in the same error all the time: JSON Parse error: Unexpected EOF
I have tried to find an answer online and attempted a lot of suggestions, but none of them worked.
In the development environment, I am accessing the API over a local network.
fetchUsers(timer) {
let data = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Bearer ' + this.state.token.access_token
}
}
fetch('http://' + this.state.ip + ':5000/api/Devices/031.01.0657/LiveState', data)
.then(response => response.json())
.then(responseJson => {
this.setState({
isLoading: false,
error: false,
userDataSource: responseJson,
refreshing: false,
time: timer
}, function () {
// If success, do something (I never make it to this part)
});
})
.catch(error => {
this.setState({
isLoading: false,
error: true
})
console.error(error);
});
}
I have of course been using other means to see what the API returns:
The JSON I get in response when using the API interface:
{
"device": null,
"patient": null
}
The JSON I get in response when using the Postman client:
{
"device": null,
"patient": null
}
Using the exact same URL as in the code. The returned JSON also passes as valid JSON.