React native React本机fetch api调用与post请求失败
我创建了一个fecthapi调用,如下所示React native React本机fetch api调用与post请求失败,react-native,fetch,React Native,Fetch,我创建了一个fecthapi调用,如下所示 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:
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)
},
)
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.props.Login.User.access_token,
},
body:JSON.stringify(model)
}
……等等。。但它并没有达到预期的效果,但我在《邮递员》中也做了同样的测试,我得到了结果
stringify(模型)将如下所示
{
"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
}
]
}
试试这个
谢谢。我已经弄明白了问题所在。我刚刚更改了标题,如下所示
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)
},
)
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + this.props.Login.User.access_token,
},
body:JSON.stringify(model)
}
如果您在此处托管API共享,则一切正常不起作用。