Android 如何在react native中从服务器api获取数据
各位。我将从服务器API获取数据。 下面是邮递员截图。 我使用了以下代码:Android 如何在react native中从服务器api获取数据,android,ios,react-native,mobile,cross-platform,Android,Ios,React Native,Mobile,Cross Platform,各位。我将从服务器API获取数据。 下面是邮递员截图。 我使用了以下代码: await fetch('http://wichz.com/api/test/token', { method: 'GET', headers:{ "Accept": 'application/json', "Content-Type": 'application/json; charset=utf-8',
await fetch('http://wichz.com/api/test/token', {
method: 'GET',
headers:{
"Accept": 'application/json',
"Content-Type": 'application/json; charset=utf-8',
"Auth": token_variable,
}
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(function(error) {
Alert.alert('Warning!', 'Network Error.');
});
但服务器不能接受头,所以响应是令牌失败。
然后使用的令牌是正确的,服务器可以响应我的请求。
但服务器无法在标头中获取“Auth”字段,响应为
{
"status": 0,
"data": null
"error": "Invalid token"
}
下面是postman中的响应标题
如何从服务器获取数据。如果有人能解决这个问题,请提前通知我。谢谢