在NodeJS中创建HTTPS客户端

8

我一直在努力弄清如何使用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)

我已经在谷歌上搜了半个小时的答案,并阅读了http://nodejs.org/上的文档。我缺少什么?

2个回答

16

3
如果您使用node.js作为客户端,您应该能够简单地将http替换为https。这是根据以下网站的说法:https://github.com/danwrong/Restler/
"Transparently handle SSL (just specify https in the URL)"

我会研究一下使用Restler,之前我还没有接触过它。在检查源代码时,我注意到它使用了“https”模块,这帮助我找到了我的问题的答案。谢谢! - Ryan Tenney

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接