0

cakephp 4.4.6

I use vuejs as frontend, all works fine, but I have csrf problems to send XMLHttpRequest with post request. CsrfProtectionMiddleware is activated.

It works fine when post data are send from an html "form" (_csrfToken is in a hidden field).

But if post data are send from an axios request, cakephp backend cannot get the csrf token.

Here is the front code:

axios .post("/equipes/delete", { headers: { "X-Requested-With": "XMLHttpRequest", 'X-CSRF-Token': this.csrftoken, }, params: { // csrfToken: this.csrftoken, // _csrfToken: this.csrftoken, id: id, }, }) .then((response) => { }) .catch((e) => { console.log(this.$options.name + ": method confirmationDelete : error"); }); 

The parameters send to the cakephp backend: enter image description here

And the error returned :

enter image description here

Any ideas ? Thanks

2
  • 1
    stackoverflow.com/questions/44617825/… Commented Oct 26, 2022 at 11:13
  • Thanks @ndm, it works fine (axios post parameters were not correct) Commented Oct 27, 2022 at 19:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.