7
<?xml version="1.0" encoding="utf-8"?>
<rsp stat="ok">
        <image_hash>cxmHM</image_hash>
        <delete_hash>NNy6VNpiAA</delete_hash>
        <original_image>http://imgur.com/cxmHM.png</original_image>
        <large_thumbnail>http://imgur.com/cxmHMl.png</large_thumbnail>
        <small_thumbnail>http://imgur.com/cxmHMl.png</small_thumbnail>
        <imgur_page>http://imgur.com/cxmHM</imgur_page>
        <delete_page>http://imgur.com/delete/NNy6VNpiAA</delete_page>
</rsp>

This is the typical response I'll receive. I've tried the following but I get an error telling me that Non White Space Characters Cannot Be Added To Content.

XDocument response = new XDocument(w.UploadValues("http://imgur.com/api/upload.xml", values));    
H H
  • 263,252
  • 30
  • 330
  • 514
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254

2 Answers2

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

But that Error could as well come from the values.

H H
  • 263,252
  • 30
  • 330
  • 514
  • in case you are assuming UTF-8, just use `Encoding.UTF8.GetString` instead of `Encoding.ASCII.GetString` – Luke Nov 27 '17 at 14:50
5

I experienced it is better to load the bytes in a MemoryStream and feed that to the XDocument. This way you won't have to fix any white-space issues.

byte[] responseData = w.UploadValues("http://imgur.com/api/upload.xml", values);
using(var ms = new MemoryStream(responseData)) 
{
var responseXml = XDocument.Load(ms);
}