HttpWebRequest.UserAgent:它有什么作用
我读了这个 MSDN,并运行了它的示例。 http://msdn.microsoft.com/en-us /library/system.net.httpwebrequest.useragent.aspx
当我将 uSerAgnet 更改为“blah”之类的内容时,输出是错误的,但是当我使用示例中的相同内容时,即使我注释掉设置 UserASgent 的代码行,输出是正确的。
UserAgent 到底是什么?我应该什么时候设置它?如何知道我应该将其设置为什么值?
谢谢
I read this MSDN like about it and ran its example.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent.aspx
when I change the uSerAgnet to something like "blah", the output is wrong but when I use the same thing that is in the example of even when I comment out the line of code that is setting the UserASgent, the output is correct.
what is UserAgent at all ? when should I set it ? How to know to what value should I set it ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户代理用于识别客户端、操作系统等,最常用于浏览器中。您可以使用用户代理来指定您是谁,并且 Web 服务器可以返回包含适合您客户端的数据的响应。例如,我用来访问此网站的用户代理是:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/ 533.4
如果我是一个网络爬虫,我会使用其他东西,网络服务器将识别为爬虫,并且网络服务器(网络开发人员)可以返回优化的页面以进行索引。除非您确实需要,否则我建议您不要提出自己的用户代理,缺乏标准化是该领域的一个足够大的问题。
有什么特别的原因需要你去干扰用户代理吗?
此页面包含许多已知用户代理的列表。
The User Agent is used to identify the client and operating system etc. It's most commonly used in browsers. You can used the User Agent to specify who you are, and the web server can return a Response with data appropriate for you client. For instance my User Agent I used to access this site is:
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Had I instead been a web crawler I would have used something else, something the web server would identify as a crawler, and the web server (the web developer) could have return a optimized page for indexing.Unless you really need to, I would advice against coming up with you own User Agent, lack of standardization is a big enough issue in this field.
Are there any reason in particular you need to mess with the User Agent?
This page contain a list of many known User Agents.