Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:09:26+00:00 2026-06-09T00:09:26+00:00

I am trying to load an HttpWebResponse into an XmlDocument and am getting the

  • 0

I am trying to load an HttpWebResponse into an XmlDocument and am getting the exception “Data at the root level is invalid. Line 1, position 1”. If I output the response to the Console I get “system.net.connectstream”. The credentials don’t seem to be my problem because if I enter an incorrect password my exception changes to the 404 error. Here is my code…

string username = "username";
string password = "password";
string url = "https://myurl.com";

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Credentials = new NetworkCredential(username, password);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
Console.WriteLine(response.GetResponseStream());
xmlDoc.Load(response.GetResponseStream());

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:09:27+00:00Added an answer on June 9, 2026 at 12:09 am

    Calling ToString on GetResponseStream() isn’t going to do much for you – Stream.ToString isn’t overridden.

    I suggest you use something like this for debugging::

    // Prefer casting over "as" unless you're going to check it...
    using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
    {
        using (Stream stream = response.GetResponseStream())
        {
            // For diagnostics, let's assume UTF-8
            using (StreamReader reader = new StreamReader(stream))
            {
                Console.WriteLine(reader.ReadToEnd());
            }
        }
    }
    

    Then replace the middle section (with StreamReader) with the XmlDocument.Load call.

    I suspect you’ll see that it’s basically invalid XML, but the above should show you what it really is.

    EDIT: Your comment shows the data as:

    {"messages":{"message":"1 Device(s) returned."},"devices":{"device":
        {"@id":"00","uuid":"00000000","phonenumber":"000‌​000",
         "user name":"0000","name":"Guy,Somebody","platform":"platform","os":"III",
         "version":"1‌​.1.1"}},"appName":"someApp"}
    

    That’s JSON. It’s not XML. Don’t try to load it as XML. You have two options:

    • Change what you’re requesting so that you get an XML response back, if the server supports it
    • Parse it as JSON (e.g. with Json.NET) instead of as XML.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to load a small .txt file into mysql but get all my data
Trying to load data into a drop down list when a user selects one
trying to load some data into a table that has a foreign key constraint.
Trying to load content into a div, then on click load the previous content
trying to load in a bunch of images into a list from a directory...my
i am trying load file after it created from /stext command line but its
trying to load a single field into an array and then loading that in
Im trying to load a xml file into a dataset and generate crystal report
i am trying to load r1,r2,r3 column to a checkboxlist, but the output is
I'm trying to load a local image into a JTextPane, and the program relentlessly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.