我有以下最小的基本 express Node js 应用程序:
var express = require ('express');
var app = express ();
app.get ('/', function (req, res) {
res.send ('Hello');
});
app.listen (3000);
当我在 localhost:3000 上访问该站点时,我得到如下响应:
如果我将 res.send ('Hello');
更改为 res.end ('Hello');
,响应将是不同的字体,例如:
我很好奇;为什么不同?
最佳答案
如果你传递一个字符串给res.send()
,它automatically assumes a Content-Type of html .
res.end()
只是在响应流上调用 Node 的底层 end()
实现,因此没有对 Content-Type 做出任何假设。
它呈现不同的原因仅仅是浏览器决定为 HTML 呈现“漂亮”的默认字体,以及为未知内容类型呈现样式较少的字体。
关于node.js - 为什么 res.end 和 res.send 的字体不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774811/