Node.js HTTPS 400错误 - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' [英] Node.js HTTPS 400 Error - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
问题描述
我正在编写一个Node.js应用程序,它必须从我们的一个内部API请求一些数据。棘手的部分是我请求数据的服务器有一些限制:
I'm writing a Node.js app that has to request some data from one of our internal APIs. The tricky part is that the server I'm requesting data from has certain limitations:
- 请求必须在HTTPS协议(不是HTTP)上进行)
- 请求必须使用LAN IP地址,因为域名不能在内部工作
- 请求似乎必须从外部域名,因为这是虚拟主机的设置。
为了做到这一点,我正在运行看起来像这样的代码:
In order to do this, I'm running a bit of code that looks like this:
var headers = {
Host: externalHostname,
Hostname: externalHostname,
};
var options = {
host: InternalIP,
path: path,
method: 'GET',
headers: headers
};
var req = https.request(options, function(res) {
res.setEncoding('utf8');
var data = "";
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
//Do something with that data
});
res.on('error', function(err) {
console.log("Error during HTTP request");
console.log(err);
});
});
req.end();
不幸的是,我收到了400(您的浏览器发送了此服务器无法理解的请求)错误作为回应。我已经检查过主机名,IP地址和路径名都是正确的(我可以在我的浏览器中测试它们,一切都很好)。
Unfortunately, I'm getting a 400 (Your browser sent a request that this server could not understand) error as a response. I've double and triple checked that the hostname, ip address, and path name are all correct (I can test them from within my browser, and all is good).
我输出了我的响应变量(res),并且收到了authorizationError值 UNABLE_TO_VERIFY_LEAF_SIGNATURE
。我不确定那是什么,或者这是我的问题,但它是我能找到的唯一有用的信息。
I did an output of my response variable (res), and am receiving an authorizationError value of UNABLE_TO_VERIFY_LEAF_SIGNATURE
. I'm not sure what that is, or if it's my problem, but it's the only useful bit of information I could find.
我把我的回复的完整输出变量此处。
I put a full output of my response variable here.
关于可能导致什么的任何想法这个?
Any ideas on what might be causing this?
更新:我想通了!我试图通过传递?PHPSESSID = asdad
GET
变量来验证服务器,但是他们已经禁用了该变量。我能够通过在Cookie标头中设置 PHPSESSID
来使其工作。
Update: I figured it out! I was trying to authenticate with the server by passing a ?PHPSESSID=asdad
GET
variable, but they have that disabled. I was able to make it work by setting PHPSESSID
in the Cookie header.
推荐答案
设置此 process.env ['NODE_TLS_REJECT_UNAUTHORIZED'] ='0';
这篇关于Node.js HTTPS 400错误 - 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!