Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从restapi读取XML_C#_Xml_Rest - Fatal编程技术网

C# 从restapi读取XML

C# 从restapi读取XML,c#,xml,rest,C#,Xml,Rest,我正在用C#编写一个小型控制台应用程序,向restapi发送请求并接收XML响应。下面是我的代码 using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); XmlDocum

我正在用C#编写一个小型控制台应用程序,向restapi发送请求并接收XML响应。下面是我的代码

 using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader.ReadToEnd());
                Console.Write(xmlDoc);

            } 
我已经检查使用小提琴,我得到200响应代码和结果。但是在执行
xmlDoc.Load(reader.ReadToEnd())时我收到错误消息

有谁能帮我解决这个问题吗?或者有没有其他方法可以做到这一点

我想将响应XML结果写入文件。

提前感谢

试试这个:

        string response;
        try
        {
            using (StreamReader streamIn = new StreamReader((webRequest.GetResponse()).GetResponseStream()))
            {
                response = streamIn.ReadToEnd();
                streamIn.Close();
            }
        }finally
        {webRequest.Abort();}

       XDocument xDoc = XDocument.Parse(response);

你犯了什么错误?有没有关于你犯了什么错误的线索?