POST 요청을 보내려고 하는데 헤더와 콘텐츠는 설정해 두었는데 원하는 결과를 얻지 못하고 있습니다:
export default async function postNewTopic(req, res) {
axios.post(`url/posts.json?title="${req.query.title}"&raw=${req.query.content}&category=1`, {
headers: {
"Api-Key": token ,
"Api-Username": {My key}
}})
.then(function (response) {
res.json(response.data);
})
.catch(function (error) {
const err = error?.response?.data || error;
res.status(error.status || error.statusCode || +error.code || 500).json(err)
})
}
그리고 여기는 프론트엔드 코드입니다:
const createTopic = () => {
axios.post(`api/post-new?title=${title}&raw=${content}&category=1`, {
headers: {
"Authorization": 'Bearer' + "",
"Api-Key": token ,
"Api-Username": ""
}})
.then(function (response) {
res.json(response.data);
})
.catch(function (error) {
const err = error?.response?.data || error;
console.log(error.response.data)
})
}