Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.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# 如何将byte[]响应转换为有效的XDocument?_C#_.net_Webclient_Linq To Xml_Httpwebresponse - Fatal编程技术网

C# 如何将byte[]响应转换为有效的XDocument?

C# 如何将byte[]响应转换为有效的XDocument?,c#,.net,webclient,linq-to-xml,httpwebresponse,C#,.net,Webclient,Linq To Xml,Httpwebresponse,但是这个错误也可能来自于我经历过的值,最好将字节加载到MemoryStream中并将其馈送到XDocument。这样,您就不必修复任何空白问题 byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values); string responseText = Encoding.ASCII.GetString(responseData); // ASCII assumed XDocument respns

但是这个错误也可能来自于我经历过的

,最好将字节加载到MemoryStream中并将其馈送到XDocument。这样,您就不必修复任何空白问题

byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
string responseText = Encoding.ASCII.GetString(responseData);  //  ASCII assumed
XDocument respnseXml = XDocument.Parse(responseText); 

如果您使用UTF-8,只需使用
Encoding.UTF8.GetString
而不是
Encoding.ASCII.GetString
XDocument response = new XDocument(w.UploadValues("http://imgur.com/api/upload.xml", values));    
byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
string responseText = Encoding.ASCII.GetString(responseData);  //  ASCII assumed
XDocument respnseXml = XDocument.Parse(responseText); 
byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
using(var ms = new MemoryStream(responseData)) 
{
var responseXml = XDocument.Load(ms);
}