2012-04-02 6 views
1

をBROWSERIDしようとしているときに、私はどのようにhttpでこれを書くことについて、requestのような他のモジュールを使用するつもりはない、
ポストを播種しながら、私は何を考慮すべきですbrowseridに?「のNode.js:スロー電子; // process.nextTickエラー、」

エラー:

$ coffee server.coffee 
    info - socket.io started 
to send 
to write 
end? 

node.js:201 
    throw e; // process.nextTick error, or 'error' event on first tick 
     ^
Error: getaddrinfo ENOENT 
    at errnoException (dns.js:31:11) 
    at Object.onanswer [as oncomplete] (dns.js:140:16) 

ソース:長いスタックトレースと

ll = console.log 

fs = require 'fs' 
page = fs.readFileSync 'page.html', 'utf-8' 
query = require 'querystring' 

client = fs.readFileSync 'client.coffee', 'utf-8' 
page = page.replace '@@@', client 

handler = (req, res) -> 
    res.writeHead 200, 'Content-Type': 'text/html' 
    res.end page 

http = require 'http' 
app = http.createServer handler 
app.listen 8000 

io = (require 'socket.io').listen app 
io.set 'log level', 1 
io.sockets.on 'connection', (socket) -> 
    socket.emit 'ready', 'go' 

    socket.on 'assertion', (data) -> 
    msg = query.stringify 
     assertion: data 
     audience: 'localhost:8000' 

    options = 
     host: 'https://browserid.org' 
     path: '/verify' 
     method: 'POST' 
     headers: 
     'Content-Type': 'application/x-www-form-urlencoded' 
     'Content-Length': msg.length 
    ll 'to send' 
    request = http.request options, (response) -> 
     str = '' 
     ll 'prepare' 
     response.on 'data', (chunk) -> 
     str += chunk 
     ll str 
     response.on 'end', -> 
     ll str 
    request.write msg 
    ll 'to write' 
    request.end() 
    ll 'end?' 

http.request documentationを見て

$ coffee server.coffee 
     info - socket.io started 
    to send 
    to write 
    end? 
    Uncaught Error: getaddrinfo ENOENT 
     at errnoException (dns.js:31:11) 
     at Object.onanswer [as oncomplete] (dns.js:140:16) 
    ---------------------------------------- 
     at EventEmitter.on 
     at Array.<anonymous> (http.js:1147:12) 
     at EventEmitter._tickCallback (node.js:192:40) 
    ---------------------------------------- 
     at EventEmitter.nextTick 
     at ClientRequest.onSocket (http.js:1115:11) 
     at Agent.addRequest (http.js:938:9) 
     at new ClientRequest (http.js:1068:16) 
     at Object.request (http.js:1331:10) 
     at Socket.<anonymous> (/home/chen/code/home/git/docview/learning/coffee/browserid/server.coffee:52:22) 
     at Socket.$emit (events.js:67:17) 
     at SocketNamespace.handlePacket (/usr/lib/nodejs/socket.io/lib/namespace.js:335:22) 
    ---------------------------------------- 
     at EventEmitter.on 
     at SocketNamespace.<anonymous> (/home/chen/code/home/git/docview/learning/coffee/browserid/server.coffee:37:19) 
     at SocketNamespace.$emit (events.js:88:20) 
     at connect (/usr/lib/nodejs/socket.io/lib/namespace.js:292:10) 
     at /usr/lib/nodejs/socket.io/lib/namespace.js:308:13 
     at SocketNamespace.authorize (/usr/lib/nodejs/socket.io/lib/namespace.js:252:5) 
     at SocketNamespace.handlePacket (/usr/lib/nodejs/socket.io/lib/namespace.js:302:14) 
     at Manager.handleClient (/usr/lib/nodejs/socket.io/lib/manager.js:669:30) 
    ---------------------------------------- 
     at EventEmitter.on 
     at Object.<anonymous> (/home/chen/code/home/git/docview/learning/coffee/browserid/server.coffee:35:14) 
     at Object.<anonymous> (/home/chen/code/home/git/docview/learning/coffee/browserid/server.coffee:71:4) 
     at Module._compile (module.js:441:26) 
     at Object.run (/usr/lib/nodejs/coffee-script/lib/coffee-script/coffee-script.js:68:25) 
     at /usr/lib/nodejs/coffee-script/lib/coffee-script/command.js:135:29 
     at /usr/lib/nodejs/coffee-script/lib/coffee-script/command.js:110:18 
     at [object Object].<anonymous> (fs.js:115:5) 
     at [object Object].emit (events.js:64:17) 
    Uncaught undefined 

node.js:201 
    throw e; // process.nextTick error, or 'error' event on first tick 
     ^
+0

は役に立ちます:https://github.com/tlrobinson/long-stack-traces –

答えて

1

、我々は見つける:

Options:

  • host: A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
  • hostname: To support url.parse() hostname is preferred over host
  • port: Port of remote server. Defaults to 80.

あなたは代わりにこれらのオプションを試してみてください:

options = 
    hostname: 'browserid.org' 
    port: 443 
    path: '/verify' 
    method: 'POST' 
    headers: 
    'Content-Type': 'application/x-www-form-urlencoded' 
    'Content-Length': msg.length 

編集:http.requestはこのために、あなたはhttps.requestを使用する必要がある、SSLリクエストには機能しません。それに変更すると他のエラーも修正され、デフォルトのポートは443になりますので、必要に応じてオプションから省略することができます。

+0

ありがとうございます。今のようだ。しかし、私は別の問題があるhttp://stackoverflow.com/questions/9286326/node-js-proxy-server-posts-to-http-server-and-dies-when-http-server-is-closed – jiyinyiyong

+0

私は、私の答えを聞いてうれしかった。もしあなたが満足していたら、それを受け入れることを検討してください。将来の訪問者のために、そしてあなたと私の両方のカルマの良さのために! –

+1

@jiyinyiyong:HTTPSリクエストには 'https.request'を使う必要があります。あなたは同じエラーメッセージが表示されますが、おそらく他の質問には関係しません。 –

関連する問題