Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read a secure XML URI in C#?

Tags:

c#

xml

https

I am trying to read a secure XML document from a URI in C#. I understand the basics of the XmlReader class. However I cannot figure out how to supply a username and password for the URI in code. I get the feeling it has something to do with an XmlSecureResolver object. But I can't figure out how to set the username and password. Can anyone help me with how to set the credentials?

Thanks, Corey

like image 477
Corey Burnett Avatar asked Feb 21 '23 15:02

Corey Burnett


1 Answers

I think this should do the trick:

WebRequest request = WebRequest.Create(url);
request.Credentials = new NetworkCredential("usernamne", "password");

using (WebResponse response = request.GetResponse()) 
{
    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
    {
        // Blah blah...
    }
}
like image 115
ilivewithian Avatar answered Feb 28 '23 20:02

ilivewithian