我花了很长时间才弄清楚如何使用 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/ http://nodejs.org/。我缺少什么?
事实证明我使用的是旧版本的 Node 文档,其中不包含对https
模块。参考当前的文档,我发现http://nodejs.org/docs/latest/api/https.html#https_https_get_options_callback http://nodejs.org/docs/latest/api/https.html#https_https_get_options_callback,它提供了一个示例:
https.get({ host: 'encrypted.google.com', path: '/' }, function (res) { … });
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)