【问题标题】:Posting xml data back extra html tags get inserted将 xml 数据发回额外的 html 标记被插入
【发布时间】:2012-10-05 23:16:45
【问题描述】:

我有一个网站在http://www.xyz.com/test.aspx 上向我们的页面发出请求,作为回报,我们必须发回响应。以下代码是发送响应的内容。问题是它将 XML 数据发回,但它也发送了 test.aspx 的代码 我不知道如何删除它。

Random random = new Random();
int randomNumber = random.Next(0, 10000000);
attrval = randomNumber + "tty";
strCXML = "<?xml version=" + "\"" + "1.0" + "\"" + " encoding=" + "\"" + " UTF-8" + "\"" + " ?>";      
strCXML =strCXML+"<!DOCTYPE cXML SYSTEM " + "\"" + "http://xml.cxml.org/schemas/cXML/1.2.023/cXML.dtd" + "\"" + ">";
strCXML = strCXML + " <cXML payloadID=" + "\"" + attrval + "\"" + " timestamp=" + "\"" + strTimeStamp + "\"" + ">";
strCXML = strCXML + "<Response>";
strCXML = strCXML + "   <Status code=" + "\"" + 200 + "\"" + " text=" + "\"" + "success" + "\"" + ">" + "</Status>";
strCXML = strCXML + "   <PunchOutSetupResponse> ";
strCXML = strCXML + "     <StartPage>";
strCXML = strCXML + "       <URL>" + strMySiteURL + "</URL>";
strCXML = strCXML + "     </StartPage>";
strCXML = strCXML + "   </PunchOutSetupResponse>";
strCXML = strCXML + " </Response>";
strCXML = strCXML + "</cXML>";
Response.Write(strCXML);

这工作正常,只是当它发回数据时它还包括 test.aspx 页面的 html

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title></head>
<body>

</body>
</html>
  Please contact support with the Error Reference Number: ANERR-10000000000000000057040121 for more details</Status>
        </Response>
</cXML>

任何想法我如何发回它,所以它只发回上面的 XML 数据。

【问题讨论】:

  • 为什么要手动构建 XML?

标签: c# asp.net xml cxml


【解决方案1】:

您需要在将xml写入流后调用Response.End,否则站点将继续呈现页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-09
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    相关资源
    最近更新 更多