方法:1、使用“res.write(93f0f5c25f18dab9d176bd4f6de5d30e8975901ff2b8508c69e86f12f503c7b29c3bca370b5104690d9ef395f2c5f8d1)”语句;2、使用“res.setheader()”或“res.writeheader()”设置content-type类型。
本教程操作环境:windows7系统、nodejs 12.19.0版,dell g3电脑。
nodejs设置编码的方法
1、使用res.write()设置meta标签
res.write("<head><meta chartset='uft-8'/></head>")
2、使用res.setheader()或res.writeheader()设置content-type
res.setheader("content-type","text/html;charset=utf8");res.writeheader(200,{"content-type":"text/html;charset=utf8"})
说明:content-type
content-type(内容类型),一般是指网页中存在的 content-type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些 php 网页点击的结果却是下载一个文件或一张图片的原因。
content-type 标头告诉客户端实际返回的内容的内容类型。
语法格式:
content-type: text/html; charset=utf-8content-type: multipart/form-data; boundary=something
【推荐学习:《nodejs 教程》】
以上就是使用nodejs如何设置编码的详细内容。