Skip to content

Instantly share code, notes, and snippets.

@sheminanto
Created November 24, 2022 10:40
Show Gist options
  • Save sheminanto/e332b6e89c6541df476f5cd61b146759 to your computer and use it in GitHub Desktop.
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
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