简体   繁体   English

NodeJS-发出HTTPS GET请求

[英]NodeJS - Make HTTPS GET request

I'm not able to execute an HTTPS request from my NodeJS webserver to a public service. 我无法执行从我的NodeJS网络服务器到公共服务的HTTPS请求。

Here the code: 这里的代码:

const https = require('https');

        var httpOptions = {
            hostname: <URL>,
            path: <PATH>,
            port:443,
            method:"GET",
            auth: <USERNAME>+":"+<PASSWORD>
        }
        console.log(httpOptions);    

        https.get(httpOptions,(res)=>{
            console.log('statusCode:', res.statusCode);

            res.on('data', function (chunk) {
                console.log("DATA");
            });

            res.on('end',(error)=>{
                console.log("END");
            });

            res.on('error',(error)=>{
                console.log("ERRROR");
            });

        });

I get as response this: 我得到的回应是:

Error: Hostname/IP doesn't match certificate's altnames: "Host: https. is not in the cert's altnames: DNS:*.ng.bluemix.net, DNS:ng.bluemix.net"

How can I solve this issue? 我该如何解决这个问题?

您正在使用的网址似乎没有有效的SSL证书。

The problem was the wrong hostname. 问题是主机名错误。 I removed the protocol at the beginning: 我在一开始就删除了协议:

"https://example.com" => "example.com"

After that it worked well. 之后,它运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM