0

I have a XML URL and it use windows credential. I wrote a test code but I have no idea how to use in XmlReader.

Could anyone help me to authentication code on Xmlreader?

Here is simple base code.

            WebRequest request = WebRequest.Create(@"https://xmllink?format=XML");
            request.Credentials = new NetworkCredential(@"username", "password");

            using (WebResponse response = request.GetResponse())
            {
                using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "title")
                        {
                            string s1 = reader.ReadElementString();
                            Console.WriteLine("Name = " + s1);

                        }
                        
                    }
                    // Blah blah...
                }
            }

Thank you

Karippery
  • 85
  • 1
  • 9
  • XmlReader has nothing to do with credentials. What is your actual problem? – Crowcoder Mar 22 '21 at 14:02
  • I have xml url, this ink is only open with windows credentials. so if someone run my code. the code will use their windows credentials to access xml url. How should i read xml in console using C#? – Karippery Mar 22 '21 at 14:48
  • So your issue is actually calling GetResponse. I don't know what API you are calling or it's security requirements. Consult its documentation or contact support – Crowcoder Mar 22 '21 at 15:00

0 Answers0