i want to send the xml of an XmlDocument
object to the HTTP client, but i'm concerned that the suggested soltuion might not honor the encoding that the Response
has been set to use:
public void ProcessRequest(HttpContext context)
{
XmlDocument doc = GetXmlToShow(context);
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
doc.Save(context.Response.OutputStream);
}
What if i changed the encoding to something else, Unicode for instance:
public void ProcessRequest(HttpContext context)
{
XmlDocument doc = GetXmlToShow(context);
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
doc.Save(context.Response.OutputStream);
}
Will the Response.OutputStream
translate the binary data that's being written to it on the fly, and make it Unicode?
Or is the Response.ContentEncoding
just informative?
If the ContentEncoding is just informative, what content encoding will the follow text strings come back in?
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.UTF16;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.ASCII;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.BigEndianUnicode;
context.Response.Write("Hello World");