tags:

views:

16

answers:

1

Is it possible to set the User-Agent string when making an HTTP request with XmlTextReader? If so, how might I go about doing that?

I am using VB.NET with the .NET 2.0 runtime, but can read your C# suggestions just fine.

Thank you for your time.

+2  A: 

You need to use the WebRequest or WebClient classes to manually download the content; they allow you to set headers.

EDIT: For example:

var request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "...";
using (var response = request.GetResponse())
using (var responseStream = response.GetResponseStream())
using (var reader = XmlReader.Create(responseStream)) {
    ...
}
SLaks
@SLaks: it would be good if you could show an example of WebRequest used with XmlReader.Create.
John Saunders
@John: Here you go.
SLaks