简体   繁体   中英

System.UriFormatException: 'Invalid URI: The Uri scheme is too long.'

I working on a small project where I am trying to read a response from a websocket and trying to load it in xmlDoc for further operations.

The following are the snippet of my code, where i get the "System.UriFormatException". The response is of XMLType

        UTF8Encoding encoder = new UTF8Encoding();
        byte[] buffer;

        buffer = encoder.GetBytes("<XML Response from a websocket>");

        string xml = Encoding.UTF8.GetString(buffer);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.Load(xml);

Is there any way by which we could overcome the exception, or what am i doing wrong in this code.

Lets visit the documentation

XmlDocument.Load(String)

Loads the XML document from the specified URL.

xmlDoc.Load(xml);

xml is not a Url

What you are most likely looking for is

XmlDocument.LoadXml(String) Method

Loads the XML document from the specified string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM