Using pm.sendRequest with an html reponse

Is it possible to render an html reponse using sendRequest?
Our logIn page uses html reponse and there’s where I obtain a csrf token to then log in, I’d like to know if I can do this as if I’m using cheerio(pm.response.text()

This is how I’m trying currently

1 Like

Hey @gerardovanegas620

Great to have you here! :trophy:

In the context of the pm.sendRequest() function - pm.response.text() wouldn’t work there as that’s a reference to the main request’s response body.

The response of that pm.sendRequest() request is being captured in the response arg so doing just response.text() would be what you need.

For example:

pm.sendRequest("", function (err, response) {

It wouldn’t actually ‘render’ that anywhere in the app (maybe the console if you log it) but it would return the response that you can use.

The way you have the cheerio reference doesn’t look quite right though, I think it might need to be something like this:

const $ = cheerio.load(response.text());
let csrfToken = $('[name=_csrf]').attr('value');

pm.globals.set("csrfToken", csrfToken);

1 Like

Hey Danny!
Thanks first for the fast response I appreciate it, second, thanks because it worked like a charm and I really wanted to take advantage of the sendRequest function