问题
I have the following minimal basic express node js application:
var express = require ('express');
var app = express ();
app.get ('/', function (req, res) {
res.send ('Hello');
});
app.listen (3000);
When I access this site on localhost:3000 I get a response that looks like:
If I change res.send ('Hello'); to res.end ('Hello');, the response is a different font like:
I am curious; why the difference?
回答1:
If you pass a string to res.send(), it automatically assumes a Content-Type of html.
res.end(), however, simply calls node's underlying end() implementation on the response stream, so no assumptions are made for the Content-Type.
The reason it renders differently is simply a browser decision to render a "pretty" default font for HTML, and a less-styled font for unknown content types.
来源:https://stackoverflow.com/questions/22774811/why-is-the-font-different-for-res-end-and-res-send