Node.js Nodejs:如何在windows-1252中发送http响应
我有一个nodejs站点,在某个时候它可以为数据库生成一个XML文件。问题是所有内容都在utf-8中,但对于这个特定的情况,我需要内容和文件都在windows-1252中Node.js Nodejs:如何在windows-1252中发送http响应,node.js,xml,http,windows-1252,Node.js,Xml,Http,Windows 1252,我有一个nodejs站点,在某个时候它可以为数据库生成一个XML文件。问题是所有内容都在utf-8中,但对于这个特定的情况,我需要内容和文件都在windows-1252中 const W1252 = require('windows-1252'); //https://www.npmjs.com/package/windows-1252 ... r.header('Content-Dispositio
const W1252 = require('windows-1252'); //https://www.npmjs.com/package/windows-1252
...
r.header('Content-Disposition', 'attachment; filename=sample.xml');
r.header('Content-Type', 'text/xml; charset=windows-1252');
r.write(W1252.encode(`<?xml version="1.0" encoding="windows-1252"?><x>€Àáção</x>`, {
'mode': 'html'
}));
r.end();
...
浏览器响应标题提到了windows-1252。我很困惑!谁能告诉我我错过了什么?非常感谢。
我将使用IConLite:
global.ICONVLITE = require('iconv-lite');
res.header('Content-Disposition', 'attachment; filename=sample.xml');
res.header('Content-Type', 'text/xml; charset=iso8859-1');
res.write(ICONVLITE.encode(`<?xml version="1.0" encoding="windows-1252"?><x>Àáção</x>`, "iso8859-1"));
r.end();
global.ICONVLITE=require('iconv-lite');
res.header('Content-Disposition','attachment;filename=sample.xml');
res.header('Content-Type','text/xml;charset=iso8859-1');
res.write(ICONVLITE.encode(`oáção`,“iso8859-1”);
r、 end();
global.ICONVLITE = require('iconv-lite');
res.header('Content-Disposition', 'attachment; filename=sample.xml');
res.header('Content-Type', 'text/xml; charset=iso8859-1');
res.write(ICONVLITE.encode(`<?xml version="1.0" encoding="windows-1252"?><x>Àáção</x>`, "iso8859-1"));
r.end();