0

如果我发送curl -k "https://abc.com?querystring"

-k 选项关闭 curl 对证书的验证

如果我想发出 GET 请求,如何在 nodejs 中执行此操作?如何以相同的方式覆盖所有 http GET 请求?

谢谢您的支持。

4

2 回答 2

1

rejectUnauthorized 选项设置为false

var https = require('https');

var req = https.request({
    hostname: 'example.com',
    port: 443,
    path: '/',
    method: 'GET',
    rejectUnauthorized: false
}, function() { ... });
于 2013-09-26T14:01:40.933 回答
0

检查以下代码:

var http = require('http');

var target = {    
    host : 'localhost',
    port : 3000,
    path : 'URL'
    //pfx: Certificate, Private key and CA certificates to use for SSL. Default is null.
    //cert: Public x509 certificate to use. Default null.
};

var Req_options = { 
    host: target.host,
    port: target.port,
    path: target.path,
    agent: false,
    method: 'GET'
};

callback = function(response) {
 var str = ''
  response.on('data', function (chunk) {
    str += chunk;
  });

  response.on('end', function () {
    console.log(str);
  });
}

var req = http.request(Req_options, callback);
req.end();


根据评论更新
在上面的代码中,我只更改了https&target如下:

var https = require('https'); 

var target = {    
    host : 'www.google.co.in',
    port : 443,
    path : '/'
};

输出如下:

 </html>
    .........
    .........
    .........
    attachEvent&&window.attachEvent("onload",n);google.timers.load.t.prt=e=(new Date).getTime();})();
</script></body></html>

有关更多信息,请查看此Node.js API 文档

于 2013-09-26T09:27:35.893 回答