我试图让我的应用程序返回“application/json”作为内容类型,当然只要响应是 json。
我试过了:
res.json(jsonContent);
response header has "Content-Type ? text/plain; charset=utf-8"
Run Code Online (Sandbox Code Playgroud)
和
res.setHeader('content-type', 'text/json');
res.send(jsonContent);
response header has "Content-Type ? text/plain; charset=utf-8"
Run Code Online (Sandbox Code Playgroud)
和
res.set('content-type', 'text/json');
res.send(jsonContent);
response header has "Content-Type ? text/plain; charset=utf-8"
Run Code Online (Sandbox Code Playgroud)
并且同时进行以上所有操作。但是我的应用程序总是将响应作为文本/纯文本而不是应用程序/json。我可能做错了什么?
正如文档解释的那样:
res.type('json'); // => 'application/json'
res.type('application/json'); // => 'application/json'
Run Code Online (Sandbox Code Playgroud)
将 Content-Type HTTP 标头设置为指定类型。
| 归档时间: |
|
| 查看次数: |
12581 次 |
| 最近记录: |