开发者

Set User-Agent when using XmlTextReader

开发者 https://www.devze.com 2023-01-16 23:39 出处:网络
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?

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

精彩评论

暂无评论...
验证码 换一张
取 消