Ich versuche, eine POST-Anfrage zu stellen und habe die Header und den Inhalt dafür festgelegt, aber ich erhalte nicht das richtige Ergebnis:
export default async function postNewTopic(req, res) {
axios.post(`url/posts.json?title=\"${req.query.title}\"\u0026raw=${req.query.content}\u0026category=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)
})
}
Und hier ist mein Frontend-Code:
const createTopic = () => {
axios.post(`api/post-new?title=${title}\u0026raw=${content}\u0026category=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)
})
}