我有一个上传控件,它从客户端调用处理程序,并将一串 xml 发送回客户端。下面的代码在 chrome 中运行良好,但在 IE 中将奇怪的 xml 发送回客户端。
处理程序代码:
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
var uploadInfo = context.Request.Files[0];
var uploadStream = uploadInfo.InputStream;
var upload = new byte[uploadInfo.ContentLength];
uploadStream.Read(upload, 0, uploadInfo.ContentLength);
var payload = System.Text.Encoding.UTF8.GetString(upload);
XmlDocument doc = new XmlDocument();
doc.LoadXml(payload);
context.Response.ContentType = "application/xml";
context.Response.Write(doc.OuterXml);
//context.Response.Write(payload);
}
}
在发送到客户端之前从处理程序调试的 XML 字符串(看起来正确)
<?xml version="1.0"?>
<ApplicationData>
<DataElement name="Comments" type="String"></DataElement>
<DataElement name="ModAuthor" type="String"></DataElement>
<DataElement name="CreateDate" type="Datetime"></DataElement>
<DataElement name="Author" type="String"></DataElement>
<DataElement name="StatusDate" type="Datetime"></DataElement>
<DataElement name="StatusDisp" type="String"></DataElement>
<DataElement name="Status" type="Number"></DataElement>
<DataElement name="Approved" type="Number"></DataElement>
<DataElement name="Submitted" type="Number"></DataElement>
<DataElement name="LogNumber" type="Number"></DataElement>
</ApplicationData>
那么被发回的 XML 字符串是:
<DIV class=e><SPAN class=b> </SPAN> <SPAN class=m><?</SPAN><SPAN class=pi>xml version="1.0" </SPAN><SPAN class=m>?></SPAN> </DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em" class=c><A class=b onfocus=h() onclick="return false" href="#">-</A> <SPAN class=m><</SPAN><SPAN class=t>ApplicationData</SPAN><SPAN class=m>></SPAN></DIV>
<DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Comments</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>ModAuthor</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>CreateDate</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Datetime</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Author</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>StatusDate</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Datetime</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>StatusDisp</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Status</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Approved</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Submitted</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV><SPAN class=b> </SPAN> <SPAN class=m></</SPAN><SPAN class=t>ApplicationData</SPAN><SPAN class=m>></SPAN></DIV></DIV></DIV>
由于某种原因,XML 正在以完全不同的格式翻译给客户端。