【发布时间】:2020-05-05 14:49:12
【问题描述】:
我用我的 Rails 数据创建了一个 API。我想从 React 添加数据,为此我使用 POST 请求:
export async function createUserCours(user_cours) {
console.log(user_cours);
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(user_cours)
};
const response = await fetch('/api/v1/cours_users', options);
console.log(response);
const data = await response.json();
return {
type: 'USER_COURS_CREATED',
payload: data
}
}
但是获取请求失败并返回 422 状态错误(无法处理的实体)。
【问题讨论】:
标签: api post react-redux fetch