2011-02-09 30 views
8

Ho avuto un po 'di tempo a capire come utilizzare Node.js (v0.3.8) per connettersi in modo sicuro a un server HTTP. Ho il seguente codice:Creare client HTTPS in NodeJS

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

quando l'eseguo, ottengo:

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) 

Sono stato googling per risposte per l'ultima mezz'ora, e di aver letto la documentazione a http://nodejs.org/. Cosa mi manca?

risposta

3

Se si utilizza node.js come client, è possibile sostituire semplicemente http per https.

Questo è secondo il seguente sito web https://github.com/danwrong/Restler/

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

Cercherò in utilizzando Restler, non avevo incontrato in precedenza. Esaminando la fonte, ho notato che utilizza il modulo 'https', che mi ha aiutato a trovare la risposta alla mia domanda. Grazie! –