日期:2014-05-17  浏览次数:20393 次

ASHX 返回 XML 中文 编码问题
我做了一个ASHX接口,接口返回以下XML格式的数据

context.Response.ContentType = "text/xml";
context.Response.Write(xml.InnerXml);
context.Response.End();


将返回信息复制保存在文本里,打开结果:


但如果将文本编码改了:


在IE上就正常显示:


我试了将输出信息的编码改成UTF-8、GB2312等,全部不行。

也试着
context.Response.ContentEncoding=...



想请教各位这个是编码问题?为什么会出现,怎么解决?

另外,这份程序在同一台服务器的不同端口正常工作,java调用也很正常.

------解决方案--------------------
 context.Response.Charset = "utf-8"; 也不行? 
------解决方案--------------------
把你的3.xml保存时候选UTF-8格式。
------解决方案--------------------
把这句给去掉
context.Response.ContentType = "text/xml"; 
------解决方案--------------------
        context.Response.CacheControl = "no-cache";
        context.Response.Clear();
        context.Response.ContentType = "text/xml";
        context.Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

你的数据没问题吗,可能有特殊字符,把xml结构破坏了,也可以无法显示