# Using pm.sendRequest with an html reponse

**URL:** <https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654>\
**Category:** Help Hub\
**Created:** [December 23, 2020, 1:12pm UTC](https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654 "2020-12-23T13:12:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerardovanegas620](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gerardovanegas620/32/6760_2.png) [@gerardovanegas620](https://community.postman.com/u/gerardovanegas620)\
**Post date:** [December 23, 2020, 1:12pm UTC](https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654/1 "2020-12-23T13:12:08Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/5/05557ebd3c2318c10c5be0aaf67a2036dc1f2370.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [December 23, 2020, 1:25pm UTC](https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654/2 "2020-12-23T13:25:23Z")

</div>

Hey @gerardovanegas620

Great to have you here! 🏆

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:

```auto
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
    console.log(response.text());
});

```

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:

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

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

```

---

<div class="post-metadata">

**Author:** ![gerardovanegas620](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gerardovanegas620/32/6760_2.png) [@gerardovanegas620](https://community.postman.com/u/gerardovanegas620)\
**Post date:** [December 23, 2020, 2:08pm UTC](https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654/3 "2020-12-23T14:08:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 7, 2023, 1:49pm UTC](https://community.postman.com/t/using-pm-sendrequest-with-an-html-reponse/18654/4 "2023-09-07T13:49:14Z")

</div>

Closed on September 7, 2023, 1:49pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
