node.js - 为什么 res.end 和 res.send 的字体不同?

标签 node.js express

我有以下最小的基本 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

如果我将 res.send ('Hello'); 更改为 res.end ('Hello');,响应将是不同的字体,例如:

res-end

我很好奇;为什么不同?

最佳答案

如果你传递一个字符串给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/

相关文章:

c# - 是否可以不断地动态混合音轨并将结果传输到浏览器?

javascript - Express Handlebars 通配符

node.js - 如何对 Google Datastore 中的大量实体进行求和?

javascript - npm 错误!请求 https ://registry. npmjs.org/node-modules 失败,原因:错误:0906D06C:PEM 例程:PEM_read_bio:无起始行

node.js - 将默认值设置为属性的新列, Mongoose 查询

node.js - MongoDB - 营业时间,按当天排序

node.js - 编译 Mongoose 后无法覆盖模型

node.js - 为什么我的 node js express 应用程序无法保持事件状态?

node.js - 相当于 ExpectedConditions.or 的 Node ,用于等待多个元素之一

node.js - 如何将 Assets 从 node.js 上传到 github 版本