I am using System.Xml.XmlTextReader
to read xml stream from a http location. Now I need support to read from a secure https site. How can I do this by providing user credentials in some way?
Asked
Active
Viewed 2,581 times
2 Answers
2
Do you already have the relevant code to use WebClient
or HttpWebRequest
? That would be my starting point - make sure you can download the data appropriately, then just pass the response stream into XmlReader.Create(Stream)
.
You should be able to test the web part of things without parsing the XML - just print out the downloaded data to make sure it looks correct.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
No, I have just used `Dim reader As XmlTextReader = New XmlTextReader(sUri)`. How do I implement `WebClient` or `HttpWebRequest` easiest to achieve what I want? – awe Oct 19 '09 at 10:06
-
I don't have time to come up with full WebClient/WebRequest examples now, but there are plenty of them on the web, and I expect MSDN has some useful sample code too. – Jon Skeet Oct 19 '09 at 10:09
2
Check out the documentation at MSDN for the HttpWebRequest.Credentials property. It contains a sample using the CredentialCache.
This may be what you need (in a integrated security scenario), but you might want to read the docs of NetworkCredential as well if you want to provide a username and password as strings.
Once you have the HttpWebRequest working you just say:
XmlTextReader rd = new XmlTextReader(yourHttpWebResponse.GetResponseStream());

Teun D
- 5,045
- 1
- 34
- 44
-
Thank you. The NetworkCredential class was really what I needed to know to get this. – awe Oct 19 '09 at 10:17