Created
November 24, 2022 10:40
-
-
Save sheminanto/e332b6e89c6541df476f5cd61b146759 to your computer and use it in GitHub Desktop.
Postman pre-request script to set csrf token as a variable before every requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pm.sendRequest({ | |
url: "localhost:3000/", | |
method: "GET", | |
header :{ | |
"accept": "*/*", | |
} | |
},(err, res)=> { | |
const $ = cheerio.load(res.text()); | |
const csrfToken = $("meta[name='csrf-token']").attr("content"); | |
pm.collectionVariables.set("xsrf-token", csrfToken); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment