2008年9月13日星期六

如何从服务器返回XML.(Return XML from .NET HTML Page Response)

自己就遇到过这种情况,从服务器返回XML内容后客户端不认。要从服务器端返回XML,需要注意以下几点。

1,在写入内容之前调用Response.ClearContent();清除ASP.NET自动附加的Header信息。

2,然后调用Response.ContentType = "text/xml"; 这样客户端才能将内容识别为XML。

3,还要注意文件编码,一般用UTF-8比较方便。

.NET server response HTML to user as default, but you can response XML text.
to do so:

1, call Response.ClearContent(); to clear any auto-add header information by ASP.NET.

2, call Response.ContentType="text/xml"; this make our client know, this is XML;

3, use UTF-8 codepage. this is default XML codepage, espesically for east-asia lanuage.

没有评论: