使用 https 下载文件的 Grunt 任务

Grunt task for downloading file with https

我需要一个繁重的任务来下载托管在 https 上的文件。该请求将包含一些参数,例如:

https://server.com/services/download?what=someFile&version=1

我尝试使用 grunt-downloadfile,但我得到的只是 ECONNREFUSED。我知道我使用的 URL 是正确的,因为我只需将它粘贴到浏览器中就可以了。

你会如何解决这个问题?我考虑过自己写grunt-execute节点脚本,但感觉像是在重新发明轮子。

这是使用 grunt-http-download 库的示例工作代码,如您所见,有一个 https 并且工作正常:

'use strict';

module.exports = function(grunt) {

    grunt.initConfig({
        download: {
            foo: {
                src: ['https://nodejs.org/static/images/logos/nodejs-green.png'],
                dest: '/tmp/'
            },
        }
    });

    require('load-grunt-tasks')(grunt);

    grunt.loadNpmTasks('grunt-http-download');
    grunt.registerTask('default', ['download']);
};

输出:

Running "download:foo" (download) task Downloading https://nodejs.org/static/images/logos/nodejs-green.png to /tmp/nodejs-green.png ...

Finished downloading https://nodejs.org/static/images/logos/nodejs-green.png.

Done, without errors.

它也适用于 grunt-downloadfile 库:

'use strict';

module.exports = function(grunt) {

    // Project Configuration
    grunt.initConfig({
        downloadfile: {
            files: [{
                url: 'https://nodejs.org/static/images/logos/nodejs-green.png',
                dest: '/tmp',
                name: 'test.png'
            }]
        },
    });

    require('load-grunt-tasks')(grunt);

    grunt.loadNpmTasks('grunt-downloadfile');
    grunt.registerTask('default', ['downloadfile']);
};

我是 grunt-downloadfile 的创建者,我对未能及时更新库和修复问题感到有点惭愧。但是今天我发布了版本 2。它支持 HTTPS。

请查看此处的文档:https://github.com/mCzolko/grunt-downloadfile