Accepted answer

Firstly, you almost had it without the XmlReader; you can't load the response straight into the XDocument, but, most of the time you can do:

XDocument docs = XDocument.Load(new StreamReader(response.GetResponseStream()));

Then check docs.Nodes.Count.

If docs is still empty, it's time to look at the response itself. Look at the response.ContentType - what is it?

Assuming the response isn't too large, look at it! You can do:

StreamReader reader = new StreamReader(response.GetResponseSteam()); string text = reader.ReadToEnd();

You can dump that string anywhere. Alternatively, if it is very big, you can save the response to disk, using either a FileStream with your Response, or, more simply WebClient.DownloadFile(url, path_to_save)

Either should be good enough to get you one step closer.



XDocument docs = XDocument.Load(responseReader.Read());


XDocument docs = XDocument.Load(responseReader);

The method for XDocument will accept an XmlReader which is what responseReader is, however you are calling the .Read() method on which only returns a boolean which is why you are getting that error.

Related Articles