api - Laravel X-CSFR-Token mismatch with POSTMAN -


i try talk rest api built laravel. call postman rejected due token mismatch. guess need include csrf token in header. need encrypted one? when insert token still error there token mismatch.

i retrieve token using:

    $encrypter = app('illuminate\encryption\encrypter');     $encrypted_token = $encrypter->encrypt(csrf_token());     return $encrypted_token; 

but supposed change on every refresh?

if aren't using forms - api example - can follow steps here https://gist.github.com/ethanstenis/3cc78c1d097680ac7ef0:

essentially, add following blade or twig header

<meta name="csrf-token" content="{{ csrf_token() }}"> 

install postman interceptor if not installed, , turn on

then, in browser log site (you need authorised), , either inspect element or view source retrieve token

in postman, set get/post etc needed, , in header create new pair

x-csrf-token        tokenvaluetobeinserted235kwgeioiulgsk 

some people recommend turning off csrf token when testing api, aren't testing you.

if find still have errors, check response using preview laravel tends explicit error messages. if nothing coming back, check php_error.log (what ever called).


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -