十六进制值0x1F''不是有效字符。第1行,第1项 [英] The '', Hexadecimal value 0x1F, is not a valid character. Line 1, Item 1

查看:729
本文介绍了十六进制值0x1F''不是有效字符。第1行,第1项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过httpwebrequest获取xml数据。以下代码运行正常。但是发生了一些变化,突然开始使我在Read()方法上出现异常,并出现错误: 十六进制值0x1F的’不是有效字符。第1行,项目1。 。在网络浏览器中,sURL为我提供了有效的xml。我不知道发生了什么变化。

I am getting xml data through an httpwebrequest. The following code was working fine. But something changed and suddenly started to give me an exception on Read() method with error : The '', Hexadecimal value 0x1F, is not a valid character. Line 1, Item 1. In web browser sURL gives me a valid xml. I dont know what changed.

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sURL);
    req.Method = "GET";
    WebResponse response = req.GetResponse();
    StreamReader resStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    XmlTextReader reader = new XmlTextReader(resStreamReader);
    while (reader.Read())
    {
       // some code
     }


推荐答案

在此 MSDN主题讨论了相同的问题,结果是,

At This MSDN Topic Same problem discussed, and result is that,


服务器有时会压缩其响应以节省带宽,当这种情况发生时,您需要在尝试之前解压缩响应阅读它。幸运的是,.NET框架可以自动执行此操作,但是,我们必须打开设置。

Servers sometimes compress their responses to save on bandwidth, when this happens, you need to decompress the response before attempting to read it. Fortunately, the .NET framework can do this automatically, however, we have to turn the setting on.

这个stackoverflow主题解决了问题

And this stackoverflow topic solves the problem

0x1F XML错误解决方案

您应该检查网址中有关可能的GZip压缩使用情况的响应。

You should check the response from your url about possible GZip compression usages.

祝您有美好的一天。

这篇关于十六进制值0x1F''不是有效字符。第1行,第1项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆