我正在尝试使用url下载文件,我需要做tls握手,因为它是https url这是我正在处理的代码,但它正在运行,但没有结果和错误
我的nodjs代码
var https = require('https');
var fs = require('fs');
var tls= require('tls');
var options = {
// These are necessary only if using the client certificate authentication (so yeah, you need them)
key: fs.readFileSync('client-private-key.pem'),
cert: fs.readFileSync('client-certificate.pem'),
// This is necessary only if the server
//uses the self-signed certificate
ca: [ fs.readFileSync('certdata') ]
};
var socket = tls.connect(443, options, function() {
console.log('client connected',
socket.authorized ? 'authorized' : 'unauthorized');
var file = fs.createWriteStream("file.xlsx");
console.log('running');
var request = http.get("https://example.com/secure/attachment/206906/fr-373_update.xlsx", function(response) {
response.pipe(file);
});
process.stdin.pipe(socket);
process.stdin.resume();
});
socket.setEncoding('utf8');
socket.on('data', function(data) {
console.log(data);
});
socket.on('end', function() {
server.close();
});