在Ria项目中经常使用ashx输出xml,直接在Chrome/FF/IE中显示正常,但是Flash读取的是都是中文乱码。
ashx默认的内容类型是"text/plain",改为"text/xml"后,Flash获取还是中文乱码;Response.Write加上<?xml version="1.0" encoding="utf-8"?>表头还是不行;使用System.Text下的特定转码还是不行;改为gb2312编码还是不行.....
多次尝试后解决方法如下:
|
1
2
3
4
5
6
|
context.Response.ContentType = "text/xml";
//获取当前的系统的编码 flash中就不会出错了 都是如果含有cdata的节点ie中会出错,flash中正常(-_-)
context.Response.ContentEncoding = System.Text.Encoding.Default;//其实只要这一句,显示会错误,但flash里面正确
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
|
web.config中加入:(实验证明,这段可以不加。.NET默认UTF-8的)
|
1
2
3
|
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"/>
</system.web>
|

本文详细介绍了在Ria项目中使用ashx输出XML时,Flash读取中文出现乱码的问题及其解决方案。通过调整Response.ContentType为text/xml,设置ContentEncoding为System.Text.Encoding.Default,并在web.config中配置requestEncoding和responseEncoding为utf-8,最终解决了Flash获取XML数据中文乱码的问题。
828

被折叠的 条评论
为什么被折叠?



