Preface Introduction
During this time, a project backend was laravel. Test through POSTMAN6 when writing API interfaces. However, after testing the form of the interface, Laravel comes with the CSRF authentication mechanism. This is embarrassing ...
So our purpose in using Postman is to test the POST request by XSRF verification. As an example of Laravel, Laravel will return to the browser's get request to write Xsrf-token in a cookie. So we need to take the xsrf-token from the cookie and send it out in the header of the POST request. To achieve cross-site request forgery verification that bypasses Laravel.
Installing the Postman Interceptor (Chrome extension feature)
Using postman If you make the data yourself by stitching the URL yourself, it is very troublesome. So choose Postman + Postman Interceptor, use Postman Interceptor can intercept the Web request, and upload to Postman History list, then we just need to modify the URL in the postman can be sent directly.
Laravel uses Chrome as an interceptor to record cookies, so install the postman's extensions on the Chrome browser first.
:https: //CHROME.GOOGLE.COM/WEBSTORE/DETAIL/POSTMAN-INTERCEPTOR/AICMKGPGAKDDGNAPHHHPLIIFPCFHICFO
Well...... Browse download install need FQ ...
Create an environment
We open the postman and click on the top right corner of the page to set the environment.
New Evnironment
Enter the new environment name and press "Add"
Select the newly created environment
send a GET request to get the XSRF token
Create a new request and add the following code to the Postman's Test label:
Pm.environment. Set ( // This is called decodeuricomponent (Pm.cookies.get ("Xsrf-token" ))
The added code is executed when the request server returns successfully, so the cookie can be obtained and stored in the postman's environment variable for use upon request.
to access the GET request you just created, click Send, check if the XSRF token is in the environment variable
post comes with xsrf tokens
Laravel presets require an HTTP header with an XSRF token when publishing
Here's the code I tested:
// web.php Route::p ost (' posttest ', ' operatecontroller@posttest '); // operatecontroller.php Public function $request { var_dump(' Post test ');}
Add post tab and add XSRF token to header
The format is: {{"Environment variable"}}: The value of the environment variable used to get.
X-xsrf-token:{{xsrf-token}}
Click Send, Print successfully
Above