react-native - 使用 post 请求响应 native-fetch api 调用失败
问题描述
我创建了一个 fecth api 调用,如下所示
var model=new UserAnswer();
model.category_id=2;
model.exam_id=this.state.datasourece.exam.id;
model.questions=this.state.answers;
fetch(
API.BASE_URL +
API.SUBMIT_EXAM,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.props.Login.User.access_token,
},
body:JSON.stringify(model)
},
)
...等等..但它不能完全按预期工作,但我在邮递员中测试过同样的结果,我得到了结果。
JSON.stringify(model) 看起来像
{
"category_id": 2,
"exam_id": 9,
"questions": [
{
"question_id": 38,
"user_answer_option_id": 145
},
{
"question_id": 308,
"user_answer_option_id": 1142
},
{
"question_id": 309,
"user_answer_option_id": 1146
}
]
}
解决方案
我已经弄清楚是什么问题。我刚刚更改了标题接受,如下所示
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.props.Login.User.access_token,
},
body:JSON.stringify(model)
}
一切都按预期工作
推荐阅读
- node.js - 围绕事件流 mapSync() 的承诺不起作用
- python - 使用正则表达式查找列表项并在 if 语句中使用该项目
- c++ - 数组成员的初始值设定项无效
- reactjs - 当开发中没有问题时,React 构建会导致 CORS 错误
- react-native - Linking.removeEventListener 所需参数
- c++ - C ++:定义一个结构,该结构将模板定义的容器保存到结构定义的类型
- c++ - 我需要将 int 参数转换为链表字段
- java - 如何从 postgresql 函数返回多行,而不是 MySQL
- r - 缺少月份或季度时删除年度值
- javascript - 带有url的jQuery幻灯片在图像之间可变淡入淡出