2011-04-20 40 views
0

我在学习node.js.我做了一个HTTP服务器:localhost:8888 /下载文件

http.createServer(function(request, response) { 
    response.writeHead(200, {"Content-Type": "test/html"}); 
    response.write("Hello World"); 
    response.end(); 
    }).listen(8888); 

当我去为localhost:8888 /,假设页面显示“Hello World”,而是,具有的“Hello World”中有一个文件的下载。这是假设发生的吗?

回答

6

看起来您已将内容类型设置为test/html而不是text/html。您的浏览器不知道如何处理test/html,因此您可以选择下载该文件。

3

“test/html”是否正确?也许可能是text/html的

response.writeHead(200, {"Content-Type": "test/html"}); 
+0

haha​​hahhaha哇,无法相信我错过!谢谢! – nowayyy 2011-04-20 22:06:41

1

你有错误的内容类型"test/html"我会让你找出正确的答案:)