您可以在网络客户端更改用户代理吗?
有很多人这样建议。
好吧,每次我做某事,它总是会变回零。
WebClient.Headers(HttpRequestHeader.UserAgent) = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; InfoPath.3)"
content = WebClient.DownloadString("http://www.google.com/search?q=kucing") 'doesn't work but working at firefox
但是来吧。我们真的必须这样做吗?
There are many that suggested that.
Well, everytime I do something it's always get changed back to nothing.
WebClient.Headers(HttpRequestHeader.UserAgent) = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; InfoPath.3)"
content = WebClient.DownloadString("http://www.google.com/search?q=kucing") 'doesn't work but working at firefox
There is a solution for C#
http://codehelp.smartdev.eu/2009/05/08/improve-webclient-by-adding-useragent-and-cookies-to-your-requests/
But c'mon. Do we really have to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您需要扩展 WebClient 类才能访问其中的一些好东西。
只需将示例类添加到项目的链接中,然后使用它而不是 webclient。您可以删除 RefreshUserAgent(),因为它所做的只是在每次调用它时选择一个随机用户代理。
Yes you need to extend the WebClient class to get access to some of the goodies inside.
Just add the example class in your link to your project and use that instead of webclient. You can remove RefreshUserAgent() as all this does is pick a random user agent each time you call it.