开发者

Set User-Agent when using XmlTextReader

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜