I'm trying to learn node.js. I made a http server:
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "test/html"});
respons开发者_StackOverflow中文版e.write("Hello World");
response.end();
}).listen(8888);
When I go to localhost:8888/, the page suppose to say "Hello World" but instead, a files download that has "Hello World" in it. Is this what is suppose to happen?
It looks like you have set the Content-Type to test/html
rather than text/html
. Your browser doesn't know how to handle test/html
so it gives you the option to download the file.
Is that "test/html" correct? Maybe could be text/html
response.writeHead(200, {"Content-Type": "test/html"});
you have the wrong content type "test/html"
I will let you figure out the right answer :)
Use
text/plain
instead of
text/html
精彩评论