如何在WCF数据服务AtomPub源上设置自定义内容类型响应标头 [英] how to set custom content-type response header on an WCF Data Services AtomPub Feed
问题描述
您好,
我开发并托管通过ATOM Feeds提供数据的WCF数据服务。我使用XmlHttpRequest对象异步加载数据。不幸的是在IE 8中我总是得到一个空的xml文档。它似乎是IE
的一种行为(或更好的说是bug?),它只在响应内容类型为text / xml时才加载xml数据。 ATOM提要的内容类型总是类似于application / atom + xml。
I develop and host a WCF Data Services that delivers data via ATOM Feeds. I use the XmlHttpRequest object to load the data asynchronously. Unfortunately in IE 8 I always get an empty xml document. It seems to be a behavior (or better say bug?) of the IE that it does only load xml data when the response content-type is text/xml. The content-type of the ATOM feed is always something like application/atom+xml.
我的想法是将响应内容类型设置为 代码中的text / xml。我试图通过多种方式来管理它,但结果仍然是内容类型始终是application / ....。
The idea I had is to set the response content-type to text/xml in code. I tried to manage this in several ways, but the result remains that the content-type is always application/... .
是否有人知道如何实现这一点。
Does anybody knows how to achieve this.
欢迎任何提示
问候
Rolf Cerff
Rolf Cerff
推荐答案
您可以阅读
responseText value作为XHR对象的字符串,然后使用MSXML DOMDocument对象解析它。有一个样本
这里的
显示了如何在尝试其中一个标志的情况下从文本创建文档;对于Web情况,你会想要使用MSXML 6并将ProhibitDTD设置为true(默认值,所以没什么可做的)。
You can read the responseText value as a string from the XHR object, then parse it using an MSXML DOMDocument object. There is a sample here that shows how to create a document from text in the context of trying out one of the flags as well; for the web case, you'll want to use MSXML 6 with ProhibitDTD set to true (the default value, so nothing to do really).
请注意,其他浏览器都有
DOMParser 也可以执行此操作。
Note that other browsers have an DOMParser object to do this as well.
这篇关于如何在WCF数据服务AtomPub源上设置自定义内容类型响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!