【发布时间】:2023-01-13 04:15:44
【问题描述】:
显然我对 HEAD 请求有些不了解。
这是 URL:“https://theweekinchess.com/assets/files/pgn/eurbli22.pgn”,我将在下面称为 <URL>。
如果我卷曲它,我会在标题中看到最后修改的条目:
curl --head <网址>
HTTP/2 200
last-modified: Sun, 18 Dec 2022 18:07:16 GMT
accept-ranges: bytes
content-length: 1888745
host-header: c2hhcmVkLmJsdWVob3N0LmNvbQ==
content-type: application/x-chess-pgn
date: Wed, 11 Jan 2023 23:09:14 GMT
server: Apache
但是,如果我使用 https 在 Node 中发出 HEAD 请求,则该信息会丢失:
https.request(<URL>, { method: 'HEAD' }, res => {
console.log([<URL>, res.headers])}).end()
这将返回:
[
<URL>
{
date: 'Wed, 11 Jan 2023 23:16:15 GMT',
server: 'Apache',
p3p: 'CP="NOI NID ADMa OUR IND UNI COM NAV"',
'cache-control': 'private, must-revalidate',
'set-cookie': [
'evof3sqa=4b412b5913b38669fc928a0cca9870e4; path=/; secure; HttpOnly'
],
upgrade: 'h2,h2c',
connection: 'Upgrade, Keep-Alive',
'host-header': 'c2hhcmVkLmJsdWVob3N0LmNvbQ==',
'keep-alive': 'timeout=5, max=75',
'content-type': 'text/html; charset=UTF-8'
}
]
【问题讨论】:
标签: node.js curl http-headers http-head