我正在调用一个 web api 服务,它从 umbraco(cms) 获取一个文本页面,并在文字控件中显示它的关联 xml。在比较源代码与 httpwebrequest 时,我得到了奇怪的 html 输出。
我在页面加载中使用此代码来调用服务
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://111.111.111.111:8080/api/PageContentApi?id=1122");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream stream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(stream))
{
string html = reader.ReadToEnd();
aboutText.Text = html;
}
}
我收到的字符串信息是:
[{"Id":1122,"Name":"sample","Alias":"bodyText","Value":"<p>This is a sample test</p>\r\n<p> </p>\r\n<p>two returns</p>\r\n<p> </p>\r\n<p>one return</p>\r\n<p> spaces spaces <strong>bold </strong><em> italic </em><span style=\"text-decoration: underline;\">underline</span></p>\r\n<p> </p>\r\n<p><img width=\"201\" height=\"75\" src=\"http://111.111.111.111/media/1001/logo.gif\" alt=\"logo\"/></p>","Version":"b8cbd32e-b946-4b1f-ae72-2564b7757479","Created":"1/1/0001 12:00:00 AM","ParentId":-1}]
当我在执行 get 后在 Firefox 中手动查看源代码时,我看到了完全不同的东西:
<ArrayOfPageContent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/name.Models"><PageContent><Alias>bodyText</Alias><Created>1/1/0001 12:00:00 AM</Created><Id>1122</Id><Name>sample</Name><ParentId>-1</ParentId><Value><p>This is a sample test</p>
<p> </p>
<p>two returns</p>
<p> </p>
<p>one return</p>
<p> spaces spaces <strong>bold </strong><em> italic </em><span style="text-decoration: underline;">underline</span></p>
<p> </p>
<p><img width="201" height="75" src="http://111.111.111.111/media/1001/logo.gif" alt="logo"/></p></Value><Version>b8cbd32e-b946-4b1f-ae72-2564b7757479</Version></PageContent></ArrayOfPageContent>
为什么我会看到不同类型的响应,以及将这个从 umbraco 抓取的内容渲染到 ASP 网页的最佳方式是什么。