1

我尝试过,https.request但是当我想访问 cookie 响应时,这不会出现在资源标题中。HTTP/HTTPS。

示例代码:

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.
})

支持 Cookies 吗?谢谢

PS:我typescript用来编写和ts-node运行这个脚本。

4

1 回答 1

0

你可能想要 npm 的 cookie-parser 包,然后添加

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

到 app.js 文件的顶部,并且

app.use(cookieParser());

到你的中间件。然后 Cookie 将以 req.cookies 的形式提供

于 2017-09-01T03:00:40.407 回答