在node.js中调用https web服务(在代理后面)

在node.js中调用https web服务(在代理后面),node.js,https,proxy,Node.js,Https,Proxy,我正在尝试从node.js调用https web服务。我支持代理,因此我在选项中提供代理和端口以及凭据。但是我得到了以下错误 [错误:2060:Error:140770FC:SSL例程:SSL23\u GET\u SERVER\u HELLO:未知协议 :openssl\ssl\s23\u clnt.c:683: ] 以下是我试图调用https web服务的代码片段: var https = require('https'); var username = 'username'; var pa

我正在尝试从node.js调用https web服务。我支持代理,因此我在选项中提供代理和端口以及凭据。但是我得到了以下错误

[错误:2060:Error:140770FC:SSL例程:SSL23\u GET\u SERVER\u HELLO:未知协议
:openssl\ssl\s23\u clnt.c:683:
]

以下是我试图调用https web服务的代码片段:

var https = require('https'); 
var username = 'username';
var password = 'password';
var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
var data = '';
var options = { 
hostname: 'proxy', 
port: 8080, 
path: 'https://crm.zoho.com/crm/private/json/Leads/getMyRecords?authtoken=11111tsvs26677026bcba45ae3f&scope=crmapi',
headers: {
        "Proxy-Authorization" : auth
     }
};

console.log("options- " + JSON.stringify(options) + '\n');

var req = https.request(options, function(res) {

console.log("statusCode- " + res.statusCode);
console.log("headers-" + res.headers);

res.on('data', function(chunk) {
    data += chunk;
});

res.on('end', function (chunk) { 
    console.log('response-' + data);
});

});

req.end();

req.on('error', function(e) {
     console.error(e);
});
谁能帮我解决这个问题

提前感谢,,
Manoj

我错误地使用了

var https = require('https'); 
但是我的代理只需要HTTP,代理将负责完成HTTPS请求,因为您正在path参数上设置它

(...)
path: 'https://crm.zoho.com/crm/private/json/Leads/getMyRecords?authtoken=11111tsvs26677026bcba45ae3f&scope=crmapi',
(...)
这对我很有用:

// baiken9: use http here
var http = require('http');

var username = 'username';
var password = 'password';
var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
var data = '';
var options = {
  hostname: 'proxy',
  // baiken9: Proxy Port
  port: 8080,  
  // baiken9: Add method type in my case works using POST
  method: "POST", 
  // baiken9: when proxy redirect you request will use https. It is correct as is
  path: 'https://crm.zoho.com/crm/private/json/Leads/getMyRecords?authtoken=11111tsvs26677026bcba45ae3f&scope=crmapi',
  headers: {
    // baiken9: I cannot test it my proxy not need authorization
    "Proxy-Authorization" : auth,
    // baiken9: required for redirection
    host: "crm.zoho.com",
  // baiken9: length of data to send
    'content-length': 0
  }
};

console.log("options- " + JSON.stringify(options) + '\n');


var req = http.request(options, function(res) {

  console.log("statusCode- " + res.statusCode);
  console.log("headers-" + res.headers);

  res.on('data', function(chunk) {
    data += chunk;
  });

  res.on('end', function(chunk) {
    console.log('response-' + data);
  });

});

req.end();

req.on('error', function(e) {
  console.error(e);
});
输出:

statusCode- 200
headers-[object Object]
response-{"response":{"error":{"message":"Invalid Ticket Id","code":"4834"}}}

亲切问候

@baiken9即使是我的代理也只需要http。如果是这样的话,我如何纠正这个问题?你能帮我解决这个问题吗?我已经编辑了我的答案,代码中添加了一些注释