The '', Hexadecimal value 0x1F, is not a valid character. Line 1, Item 1

血红的双手。 提交于 2020-01-05 04:43:28

问题


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
     }

回答1:


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

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.

And this stackoverflow topic solves the problem

0x1F XML Error Solution

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

Have a nice day.



来源:https://stackoverflow.com/questions/50796190/the-hexadecimal-value-0x1f-is-not-a-valid-character-line-1-item-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!