title: XDocument.Load(url) Error: Data at the root level is invalid. Line 1 position 1
body: <p>I am trying to read an xml document served on a webpage. Let's say that the url is "<a href="http://myfirsturl.com" rel="nofollow">http://myfirsturl.com</a>". The xml document at that url seems fine.</p>
  
  <pre><code>        try
          {
              string url = "http://myfirsturl.com";
  
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  
              Stream stream = response.GetResponseStream();
  
              using (XmlReader reader = 
                   XmlReader.Create(new StreamReader(stream))
              {
                  var doc = XDocument.Load(reader);
                  Console.WriteLine(doc);
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex);
          }
  </code></pre>
  
  <p>I keep getting the following error:</p>
  
  <pre><code>   System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
     at System.Xml.XmlTextReaderImpl.Throw(Exception e)
     at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
     at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
     at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
     at System.Xml.XmlTextReaderImpl.Read()
     at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
     at System.Xml.Linq.XDocument.Load(XmlReader reader)
  </code></pre>
  
  <p>I have tried the exact same code with a different url and it works for example on: "<a href="http://mysecondurl.com" rel="nofollow">http://mysecondurl.com</a>".</p>
  
  <p>I need help for steps on what to do next...</p>
  
  <p>I have looked into the error and found two possible directions for a solution:</p>
  
  <ol>
  <li>The encoding of the XML returns extra characters (I don't know how to check this)</li>
  <li>The webpage is blocking the request. (I don't know how to tackle this)</li>
  </ol>
  
  <p>Thanks for your time and help :)</p>