【发布时间】:2019-03-10 11:45:41
【问题描述】:
我使用sails server api 并且我从axios 发布响应但错误500(内部服务器错误)。 这里代码客户端
export default function callApi2(endpoint, method = 'GET', body) {
let headers = { 'content-type': 'application/x-www-form-urlencoded' }
console.log(body);
return axios({
method: method,
url: `${Config.API_URL2}/${endpoint}`,
data: JSON.stringify(body),
headers: { 'content-type': 'application/x-www-form-urlencoded' },
}).catch(err => {
console.log(err);
});
这里是代码服务器
postCommunication: async (req, res)=>{
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Methods','GET, POST, PATCH, PUT, DELETE, OPTIONS');
let newCommunication = req.body;
console.log(newCommunication);
console.log(JSON.stringify(newCommunication));
let resulfCommunication = await Communication.create(JSON.stringify(newCommunication)).fetch();
return res.json(resulfCommunication);
},
【问题讨论】:
-
请输入有问题的代码而不是图片
标签: reactjs api post sails.js axios