【问题标题】:How to enable access https from curl command in nodejs如何在nodejs中从curl命令启用访问https
【发布时间】:2020-01-26 17:25:06
【问题描述】:

我的 bash 模拟器可以正确运行 curl 命令。但是当我在 nodejs 中使用 child_process 模块调用它时,我收到一个错误,指的是 libcurl 中不支持或禁用协议“'https”。

当我运行“curl 'https://ehire.51job.com/Candidate/SearchResumeNew.aspx'”时,我可以获得页面内容。

下面是nodejs代码:

var child_process = require("child_process");
var curl = "curl 'https://ehire.51job.com/Candidate/SearchResumeNew.aspx'";
var child = child_process.exec(curl, (err, stdout, stderr) =>
{
    console.log(stdout);
    console.log(err);
    console.log(stderr);
});

screenshot

【问题讨论】:

  • 我试过这个完全相同的代码,似乎没有错误。除了变量stdoutstderr 没有值并且errnull

标签: node.js curl https


【解决方案1】:

引用this,将双引号与单引号交换,反之亦然,以下代码有效:

var child_process = require("child_process");
var curl = 'curl "https://ehire.51job.com/Candidate/SearchResumeNew.aspx"';
var child = child_process.exec(curl, (err, stdout, stderr) =>
{
    console.log(stdout);
    console.log(err);
    console.log(stderr);
});

【讨论】:

    猜你喜欢
    • 2018-07-14
    • 1970-01-01
    • 2015-05-09
    • 2012-04-22
    • 2019-08-17
    • 1970-01-01
    • 2019-11-10
    • 2017-06-23
    相关资源
    最近更新 更多