Chrome 而非 IE 上的编码问题

发布于 2024-09-30 15:40:52 字数 426 浏览 1 评论 0原文

创建 XDocument 时,我收到 XmlException 并显示以下消息:

system does not support 'iso-8859-1' encoding line 1, position 31

Xml 文档的第一行如下所示:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>

这是我用来创建文档的代码:

 xDoc = XDocument.Load(webResponse.GetResponseStream());

奇怪的是,异常发生在 Chrome 和 Firefox 上,但不是 IE8 。

有什么想法吗?

When creating an XDocument I get an XmlException with the following message:

system does not support 'iso-8859-1' encoding line 1, position 31

The first line of the Xml document looks like this:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>

Here is the code I use to create the document:

 xDoc = XDocument.Load(webResponse.GetResponseStream());

The weird thing is that the exception happens on Chrome and Firefox but not IE8.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极致的悲 2024-10-07 15:40:52

许多浏览器不支持这种编码。基本上,您可以为您尝试显示的任何语言安装字体(我假设这就是您使用该编码的原因)。然后,您可以嵌入该字体以在任何本地计算机上使用。

  • code.google.com/p/chromium/issues/detail?id=31510
  • bugs.webkit.org/show_bug.cgi?id=22339

Many browsers do not support this encoding. Basically, you can install a font for whatever language you're trying to display (I'm assuming this is why you're using that encoding). Then, you can embed that font for use on any local machine.

  • code.google.com/p/chromium/issues/detail?id=31510
  • bugs.webkit.org/show_bug.cgi?id=22339
陪你到最终 2024-10-07 15:40:52

下载由 OData 的 .NET Web 服务(由 IIS 7 在本地提供)生成的 xml 文档时,我看到类似的行为。它根据浏览器显示不同的内容类型。内容类型标头以及 xml 文件的第一行都在更改。放置断点并检查“HttpWebResponse”对象或使用 Fiddler 显示:

content-type: "application/xml;charset=utf-8"         (IE)
content-type: "application/xml;charset=iso-8859-1"    (Chrome)

比较 xml 的第一行

<?xml version="1.0" encoding="utf-8" standalone="yes"?>      (IE)
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> (Chrome)

这会导致默认的 XDocument.Load(webResponse_stream) 在 Chrome 上失败。

I'm seeing similar behavior when downloading an xml doc that is generated by a .NET web service for OData (served locally by IIS 7). It shows up with different content types based on browser. Both the content-type header as well as the first line of the xml file is changing. Putting a breakpoint in and inspecting the "HttpWebResponse" object or using Fiddler shows:

content-type: "application/xml;charset=utf-8"         (IE)
content-type: "application/xml;charset=iso-8859-1"    (Chrome)

Comparing at first line of the xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>      (IE)
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> (Chrome)

This is resulting in the default XDocument.Load(webResponse_stream) to fail on Chrome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文