在执行res.send()时如何设置内容类型? [英] How to set content-type when doing res.send()?
本文介绍了在执行res.send()时如何设置内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在路由功能的末尾,当我做这样的事情时.
At the end of route function, when I do something like this.
res.send(JSON.stringify({...}));
我希望将响应的内容类型设置为文本/纯文本",但是它是文本/html".有没有办法明确设置它?我搜索了文档,但还没有线索.
I would like the content-type of response to be set as "text/plain", but it is "text/html". Is there way to set it explicitly? I search the document but no clue yet.
推荐答案
setHeader,然后发送: https://nodejs.org/api/http.html#http_response_setheader_name_value
setHeader before sending: https://nodejs.org/api/http.html#http_response_setheader_name_value
res.setHeader('content-type', 'text/plain');
res.send(JSON.stringify({...}));
这篇关于在执行res.send()时如何设置内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文