使用curl非常快curl --http2 -O "https://t1.daumcdn.net/potplayer/PotPlayer/Version/Latest/PotPlayerSetup64.exe"
nodejs
const fs = require('fs')
const http2 = require('http2')
function error({ message }) {
console.log(message)
}
const url = new URL('https://t1.daumcdn.net/potplayer/PotPlayer/Version/Latest/PotPlayerSetup64.exe')
const {
HTTP2_HEADER_STATUS,
HTTP2_HEADER_AUTHORITY,
HTTP2_HEADER_SCHEME,
HTTP2_HEADER_PATH
} = http2.constants
const h2 = http2.connect(url)
h2.on('error', error)
const req = h2.request({
[HTTP2_HEADER_AUTHORITY]: url.host,
[HTTP2_HEADER_PATH]: url.pathname,
[HTTP2_HEADER_SCHEME]: 'https',
})
req.on('response', (headers) => {
console.log(headers[HTTP2_HEADER_STATUS])
const file = fs.createWriteStream('file')
req.pipe(file)
req.on('end', () => {
h2.close()
})
})
req.on('error', error)
req.end()
使用https模块会快一点 但是没有curl快
什么原因呢