Install User-Agent when using XmlTextReader

Is it possible to set the User-Agent string when executing an HTTP request using XmlTextReader? If so, how can I do this?

I am using VB.NET with the .NET 2.0 runtime, but I can read your C # sentences perfectly.

Thank you for your time.

+5
source share
1 answer

To manually load content, you need to use the classes WebRequestor WebClient; 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)) {
    ...
}
+8
source

All Articles