[英]'Set-Cookie' is not included in the response headers
I'm trying to get the set-cookie
header from the http response, but it's not showing up for most of the requests.我正在尝试从 http 响应中获取set-cookie
标头,但它没有出现在大多数请求中。
Using https://www.southwest.com/ as an example, you can see that https://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=1345510&rnd=459203.51759912557&fare%20class=[fare%20class]&business%20or%20leisure=[business%20or%20leisure]&number%20of%20passengers=[number%20of%20passengers]&date=[date]&destination=[destination]&origination=[origination]
sets 3 cookies:以https://www.southwest.com/为例,可以看到https://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=1345510&rnd=459203.51759912557&fare%20class=[fare%20class]&business%20or%20leisure=[business%20or%20leisure]&number%20of%20passengers=[number%20of%20passengers]&date=[date]&destination=[destination]&origination=[origination]
设置 3 个 cookie:
Puppeteer code:傀儡师代码:
const puppeteer = require('puppeteer');
async function getResponseCookies() {
function handleResponse(response) {
const url = response.url();
const headers = response.headers();
const status = response.status()
if(url.includes('https://bs.serving-sys.com/Serving/ActivityServer.bs')) {
console.log('RESPONSE URL ', url)
console.log('RESPONSE HEADERS ', headers)
console.log('RESPONSE STATUS ', status)
}
}
const browser = await puppeteer.launch({
ignoreDefaultArgs: ["--enable-automation"],
executablePath: "/usr/bin/google-chrome",
headless: true,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36");
await page.on('response', async(response) => {
await handleResponse(response);
})
const urls = ['https://www.southwest.com'];
for(let url of urls) {
await page.goto(url, { timeout: 0, waitUntil: 'networkidle0' });
}
await browser.close();
}
getResponseCookies();
The above code execution outputs the following log, without any 'set-cookie' headers in the response:上面的代码执行输出以下日志,响应中没有任何“set-cookie”标头:
RESPONSE URL https://bs.serving-sys.com/Serving/ActivityServer.bs?cn=as&ActivityID=1345510&rnd=68456.37277058625&fare%20class=[fare%20class]&business%20or%20leisure=[business%20or%20leisure]&number%20of%20passengers=[number%20of%20passengers]&date=[date]&destination=[destination]&origination=[origination]
RESPONSE HEADERS { pragma: 'no-cache',
date: 'Mon, 03 Feb 2020 10:30:16 GMT',
'content-encoding': 'gzip',
server: 'Microsoft-IIS/7.5',
'x-powered-by': 'ASP.NET',
p3p: 'CP="NOI DEVa OUR BUS UNI"',
'access-control-allow-origin': '*',
'cache-control': 'no-cache, no-store',
'content-type': 'text/html; charset=UTF-8',
'content-length': '616',
expires: 'Sun, 05-Jun-2005 22:00:00 GMT' }
Any ideas why the Set-Cookie
header is missing from the response?任何想法为什么响应中缺少Set-Cookie
标头?
*Note that those cookies are returned when using Network.getAllCookies
from CDP *请注意,使用CDP 中的Network.getAllCookies
时会返回这些 cookie
According to https://github.com/puppeteer/puppeteer/issues/4918 , it looks like puppeteer is not listening to the Network.responseReceivedExtraInfo event that contains the raw headers.根据https://github.com/puppeteer/puppeteer/issues/4918 ,看起来 puppeteer 没有侦听包含原始标头的 Network.responseReceivedExtraInfo 事件。 Listening to that event did the trick for me.听那个事件对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.