http 请求头

257 阅读1分钟
  • res.setHeader('Content-Type', 'text/html');
  • res.setHeader("Content-type","application/json");
  • res.writeHead(200, { 'Content-Type': 'text/plain'});
  • res.writeHead(200, { 'Content-Type': 'text/html'});

介绍

  • 1、两者书写格式不同。
  • 2、Content-type 包含 mime-type 和 encoding 两部分。

mime-type 代表请求的资源是什么类型的资源:文本,还是图片,还是应用程序等等。

encoding 代表编码

application/json代表请求的资源是:应用程序类型下的,json类型(某类型/子类型) 类似的,也会遇到 img/bmp , text/plain

text/plain 意思是将文件设为纯文本的形式。浏览器在获取到这种文件时,不会对其进行处理。

text/html 超文本标记语言。浏览器获取到这种文件时,会自动调用html的解析器对文本进行相应的处理。