2

I try with https.request but when I want access to cookie response, this don't appear on resource headers. HTTP/HTTPS.

Example code:

let https = require('https');

https.request({
    rejectUnauthorized: false,
    hostname: 'example.com',
    port: '443',
    path: '/example.html',
    method: 'POST',
    headers: {
        "Connection": "keep-alive",
        "Accept-Encoding": "gzip, deflate, br",
        "Upgrade-Insecure-Requests": "1",
        "Content-Type": "application/x-www-form-urlencoded",
        "Cache-Control": "no-cache",
        "Pragma": "no-cache",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Accept-Language": "es-ES,es;q=0.8",
    }
}, (res: any) => {
    console.log('headers', res.headers); // this does not show 'set-cookie' property.
})

have support to Cookies? thanks

P.S: I'm using typescript to write and ts-node to run this script.

Olaf Erlandsen
  • 5,817
  • 9
  • 41
  • 73

1 Answers1

0

You probably want the cookie-parser package from npm, and add

const cookieParser = require('cookie-parser');

to the top of your app.js file, and

app.use(cookieParser());

to your middleware. Cookies will then be available as req.cookies

One Guy Hacking
  • 1,176
  • 11
  • 16
  • 2
    I think the OP is making a request with `https.request()` and wanting to get cookies from that response which is different than what you're illustrating in your answer. – jfriend00 Sep 01 '17 at 04:38