Node.js没有方法'sendHeader'
Node.js没有方法'sendHeader'
安装副本是从git clone git://github.com/joyent/node.git
安装在ubunti lucid服务器中作为Amazon EC2 AMI文件。
通过命令输出简单地说你好。
但是,当输出到浏览器,它无法正常工作。
伙计们,有任何想法来解决它?
我希望使用node.js,但似乎还没有准备好生产使用。
ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ node hello_world_server.js Server running at http://localhost:8080/ /home/ubuntu/Desktop/node/test3/hello_world_server.js:5 response.sendHeader(200, {"Content-Type": "text/html"}); ^ TypeError: Object #<ServerResponse> has no method 'sendHeader' at Server.<anonymous> (/home/ubuntu/Desktop/node/test3/hello_world_server.js:5:14) at Server.emit (events.js:45:17) at HTTPParser.onIncoming (http.js:1081:12) at HTTPParser.onHeadersComplete (http.js:87:31) at Socket.ondata (http.js:980:22) at Socket._onReadable (net.js:654:27) at IOWatcher.onReadable [as callback] (net.js:156:10) ubuntu@ip-10-129-31-63:~/Desktop/node/test3$ node -v v0.5.0-pre
代码运行
var sys = require('sys'), http = require('http'); http.createServer(function (req, res) { setTimeout(function () { res.writeHead(200, {'Content-Type': 'text/html'}); res.write('<br/><strong> Hello World!</strong>'); res.end(); }, 2000); }).listen(8000); sys.puts('Server running at http://127.0.0.1:8000/');
这是“setHeader”,而不是“sendHeader”。
不,节点还没有准备好用于生产。 这并不能阻止很多人使用它,但即使他们会告诉你,他们这样做有点疯狂。
编辑 – 其他答案可能是正确的,这可能是你正在寻找“writeHead()”。 由于我在这里所做的只是在nodejs.org上查看相当可爱的node.js文档,所以我不得不怀疑自己是否完成了这个任务。
如果您正在关注NetTuts教程,请尝试:
response.writeHead()
代替
response.sendHeader
和
response.end()
代替
response.close()
该函数可能被称为writeHead()。 “可能”,因为我不知道你的代码和你加载的库。
http://nodejs.org/docs/v0.4.1/api/http.html#response.writeHead
几乎没有人使用node.js来创build一个完整的web服务器,但是对于子function,例如聊天服务器,它已经在很多站点上被使用了。
我相信这个方法是writeHead()