Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set User-Agent when using XmlTextReader

Tags:

.net

xml

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.

like image 968
Brad Avatar asked Sep 20 '10 02:09

Brad


1 Answers

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)) {
    ...
}
like image 117
SLaks Avatar answered Nov 15 '22 10:11

SLaks