Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NickvdMeij's avatar

CSRF Token verify error

Hi,

I'm currently building an api and encountered the "TokenMismatchException" in the VerifyCsrfToken.php. I'm using postman for testing my api and i added the X-CSRF-TOKEN header in my request, but still i get the TokenMismatchException when submitting a form (through postman to a store method on an api controller). Anyone an idea how to add the csrf token to the form?

0 likes
5 replies
afrayedknot's avatar

If you are using the default Laravel 5 CSRF handler - then your header needs to be X-XSRF-TOKEN - note the xsrf not csrf

1 like
NickvdMeij's avatar

I added the header and now i get a decryption error... Any idea how to solve this? I retrieved my csrf token using Session::token() like so:

Route::get('csrf', function() {
    return Session::token();
});
cbil360's avatar

What I had to do is,add a X-XSRF-TOKEN in the header and copy paste the XSRF token value in the value field.I copied the XSRF token value from the response header of my request and added it against the X-XSRF-TOKEN . This should work pretty well as I have tested it. Laravel expects a X-XSRF-TOKEN token and we need to add it manually in case of postman

2 likes

Please or to participate in this conversation.