The '', Hexadecimal value 0x1F, is not a v

2019-07-25 00:29发布

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条回答
爷的心禁止访问
2楼-- · 2019-07-25 01:12

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.

查看更多
登录 后发表回答