您可以在网络客户端更改用户代理吗?

发布于 2025-01-01 03:56:51 字数 739 浏览 1 评论 0原文

有很多人这样建议。

好吧,每次我做某事,它总是会变回零。

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

C# 有一个解决方案 http: //codehelp.smartdev.eu/2009/05/08/improve-webclient-by-adding-useragent-and-cookies-to-your-requests/

但是来吧。我们真的必须这样做吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2025-01-08 03:56:51

是的,您需要扩展 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文