【发布时间】:2020-05-08 06:40:48
【问题描述】:
我有一个 API 端点在邮递员中运行良好,具有以下选项
上述请求可以得到200状态并得到响应。现在我正在尝试使用 fetch 方法实现与 React Native 相同的 API。
fetch('https://example.com/api/user/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Token':'xxxxxx-xxxx-xxxx-xxxx-xxxxx'
},
body: {
"useremail": "testuser@example.com",
"userpassword": "123456"
},
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
}).catch((error) =>{
console.error(error);
});
上面的代码不起作用,我得到 403 状态。
【问题讨论】:
-
在邮递员中发送原始数据,在 react-native 中发送 json 数据
-
这个可以改吗?
-
该问题与stackoverflow.com/questions/46200756/…“令牌”被视为来自反应的“令牌”
标签: reactjs rest react-native fetch