在NodeJS中创buildHTTPS客户端

我有一段时间搞清楚如何使用Node.js(v0.3.8)安全地连接到HTTP服务器。 我有以下代码:

var http = require("http"); var client = http.createClient(443, host, /* secure= */ true); var request = client.request("GET", relativeUrl, { host: host }); 

当我运行它时,我得到:

 node.js:116 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Parse Error at Client.onData [as ondata] (http.js:1287:27) at Client._onReadable (net.js:648:27) at IOWatcher.onReadable [as callback] (net.js:156:10) 

我一直在谷歌search过去半个小时的答案,并阅读了http://nodejs.org/的文档。 我错过了什么?

事实certificate,我使用的是旧版本的Node文档,其中没有包含对https模块的引用。 参考当前的文档,我发现http://nodejs.org/docs/latest/api/https.html#https_https_get_options_callback ,它提供了一个例子:

 https.get({ host: 'encrypted.google.com', path: '/' }, function (res) { … }); 

如果您使用node.js作为客户端,您应该可以简单地将httpreplace为https。

这是根据以下网站https://github.com/danwrong/Restler/

 "Transparently handle SSL (just specify https in the URL)"