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.
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.
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)) {
...
}