【问题标题】:Grunt task for downloading file with https使用 https 下载文件的 Grunt 任务
【发布时间】:2023-03-31 01:10:01
【问题描述】:

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

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

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

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

【问题讨论】:

  • 我可以看看你试过的代码吗?
  • 我不想看API代码我想看grunt文件相关代码。你注册下载任务用 grunt 命令执行了吗?
  • 是的,任务执行没有问题。如果我放 http 它可以工作(在随机站点上)如果我放 https 它不会。
  • 另外我原来链接错了库,现在修复了!

标签: javascript node.js https build gruntjs


【解决方案1】:

这是一个带有 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']);
};

输出:

运行“download:foo”(下载)任务 正在下载https://nodejs.org/static/images/logos/nodejs-green.png 到 /tmp/nodejs-green.png ...

下载完成https://nodejs.org/static/images/logos/nodejs-green.png

完成,没有错误。

它也适用于 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']);
};

【讨论】:

  • 好像图书馆可以做到。我会尽快尝试并通知您!
  • 它实际上工作得很好(第一个例子)。第二个在我的情况下没有。
【解决方案2】:

我是 grunt-downloadfile 的创建者,对我没有设法使库保持最新并解决问题感到有点羞愧。但是今天我发布了第 2 版。它确实支持 HTTPS。

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

【讨论】:

    猜你喜欢
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    相关资源
    最近更新 更多