Мне нужно поместить некоторые данные через api, вот мой код
static voteplusQuestion(data, int flag){
print('Api');
print(data);
if( flag == 1 ){
var updateQuestionData = {'Would': data.would, 'Rather': data.rather, 'wouldClick': data.wouldClick, 'ratherClick': data.ratherClick + 1, 'QuestionID': data.QuestionID,};
print(updateQuestionData);
}
if( flag == 0){
var updateQuestionData = {'Would': data.would, 'Rather': data.rather, 'wouldClick': data.wouldClick + 1, 'ratherClick': data.ratherClick, 'QuestionID': data.QuestionID,};
print(updateQuestionData);
}
return http.put(
'https://iv9803zj9d.execute-api.us-east-2.amazonaws.com/Development/would-you-rather',
headers: <String, String>{
'Content-Type': 'application/json',
},
);
}
Мне нужно поместить updateQuestionData
в API, но я не уверен, как я могу это сделать. Также вывод на печать updateQuestionData выглядит следующим образом
{Would: Shaving Cream, Rather: Soap, wouldClick: 15, ratherClick: 13, QuestionID: 16563fa7-e833-445f-a76b-a9fbaab3a301}
И Api работает в кодовой ручке, как это
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://iv9803zj9d.execute-api.us-east-2.amazonaws.com/Development/would-you-rather');
xhr.onreadystatechange = function(event) {
console.log(event);
}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'allow');
xhr.send(JSON.stringify({Would: "Coffe",Rather: "Tea", wouldClick: 15, ratherClick: 13, QuestionID: "16563fa7-e833-445f-a76b-a9fbaab3a301"}));
Я установил заголовок в функции, но теперь не знаю, как поставил тело