浏览器用户代理

Your browser sends its user agent to every website you connect to. We’ve written about changing your browser’s user agent before – but what exactly is a user agent, anyway?

您的浏览器会将其用户代理发送到您连接到的每个网站。 我们之前曾写过有关更改浏览器用户代理的文章-但是,究竟用户代理到底是什么?

A user agent is a “string” – that is, a line of text – identifying the browser and operating system to the web server. This sounds simple, but user agents have become a mess over time.

用户代理是一个“字符串”(即一行文本),用于标识Web服务器的浏览器和操作系统。 这听起来很简单,但是随着时间的流逝,用户代理变得一团糟。

基础 (The Basics)

When your browser connects to a website, it includes a User-Agent field in its HTTP header. The contents of the user agent field vary from browser to browser. Each browser has its own, distinctive user agent. Essentially, a user agent is a way for a browser to say “Hi, I’m Mozilla Firefox on Windows” or “Hi, I’m Safari on an iPhone” to a web server.

当您的浏览器连接到网站时,它的HTTP标头中包含一个User-Agent字段。 用户代理字段的内容因浏览器而异。 每个浏览器都有自己的独特用户代理。 本质上,用户代理是浏览器向Web服务器说“嗨,我是Windows上的Mozilla Firefox”或“嗨,我是iPhone上的Safari”的一种方式。

The web server can use this information to serve different web pages to different web browsers and different operating systems. For example, a website could send mobile pages to mobile browsers, modern pages to modern browsers, and a “please upgrade your browser” message to Internet Explorer 6.

Web服务器可以使用此信息将不同的网页提供给不同的Web浏览器和不同的操作系统。 例如,一个网站可以将移动页面发送到移动浏览器,将现代页面发送到现代浏览器,并将“请升级您的浏览器”消息发送到Internet Explorer 6。

检查用户代理 (Examining User Agents)

For example, here’s Firefox’s user agent on Windows 7:

例如,这是Windows 7上Firefox的用户代理:

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0

Mozilla / 5.0(Windows NT 6.1; WOW64; rv:12.0)Gecko / 20100101 Firefox / 12.0

This user agent tells the web server quite a bit: The operating system is Windows 7 (code name Windows NT 6.1), it’s a 64-bit version of Windows (WOW64), and the browser itself is Firefox 12.

该用户代理告诉Web服务器很多信息:操作系统是Windows 7(代号Windows NT 6.1),它是Windows的64位版本(WOW64),浏览器本身是Firefox 12。

Now let’s take a look at Internet Explorer 9’s user agent, which is:

现在,让我们看一下Internet Explorer 9的用户代理:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)

Mozilla / 5.0(兼容; MSIE 9.0; Windows NT 6.1; WOW64; Trident / 5.0)

The user agent string identifies the browser as IE 9 with the Trident 5 rendering engine. However, you might spot something confusing – IE identifies itself as Mozilla.

用户代理字符串使用Trident 5渲染引擎将浏览器标识为IE 9。 但是,您可能会发现一些令人困惑的地方-IE将自己标识为Mozilla。

We’ll come back to that in a minute. First, let’s examine Google Chrome’s user agent, too:

一分钟后,我们会再谈。 首先,我们还要检查一下Google Chrome浏览器的用户代理:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5

Mozilla / 5.0(Windows NT 6.1; WOW64)AppleWebKit / 536.5(KHTML,Gecko一样)Chrome / 19.0.1084.52 Safari / 536.5

The plot thickens: Chrome is pretending to be both Mozilla and Safari. To understand why, we’ll have to examine the history of user agents and browsers.

剧情变厚了:Chrome假装既是Mozilla又是Safari。 要了解原因,我们必须检查用户代理和浏览器的历史记录。

用户代理字符串混乱 (The User Agent String Mess)

Mosaic was one of the first browsers. Its user agent string was NCSA_Mosaic/2.0. Later, Mozilla came along (later renamed Netscape), and its user agent was Mozilla/1.0. Mozilla was a more advanced browser than Mosaic – in particular, it supported frames. Web servers checked to see that the user agent contained the word Mozilla and sent pages containing frames to Mozilla browsers. To other browsers, web servers sent the old pages without frames.

Mosaic是最早的浏览器之一。 它的用户代理字符串是NCSA_Mosaic / 2.0。 后来,Mozilla出现了(后来更名为Netscape),其用户代理为Mozilla / 1.0。 Mozilla是比Mosaic更高级的浏览器-特别是它支持框架。 Web服务器检查发现用户代理包含Mozilla一词,并将包含框架的页面发送到Mozilla浏览器。 Web服务器向其他浏览器发送了没有框架的旧页面。

Eventually, Microsoft’s Internet Explorer came along and it supported frames, too. However, IE didn’t receive web pages with frames, because web servers just sent those to Mozilla browsers. To fix this problem, Microsoft added the word Mozilla to their user agent and threw in additional information (the word “compatible” and a reference to IE.) Web servers were happy to see the word Mozilla and sent IE the modern web pages. Other browsers that came later did the same thing.

最终,Microsoft的Internet Explorer出现了,它也支持框架。 但是,IE没有收到带有框架的网页,因为Web服务器只是将其发送到Mozilla浏览器。 为了解决此问题,Microsoft在其用户代理中添加了Mozilla一词,并添加了其他信息(“兼容”一词和对IE的引用。)Web服务器很高兴看到Mozilla一词并向IE发送了现代网页。 后来出现的其他浏览器也做同样的事情。

Eventually, some servers looked for the word Gecko – Firefox’s rendering engine – and served Gecko browsers different pages than older browsers. KHTML – originally developed for Konquerer on Linux’s KDE desktop – added the words “like Gecko” so they’d get the modern pages designed for Gecko, too. WebKit was based on KHTML – when it was developed, they added the word WebKit and kept the original “KHTML, like Gecko” line for compatibility purposes. In this way, browser developers kept adding words to their user agents over time.

最终,一些服务器使用了Gecko这个词(Firefox的渲染引擎),并为Gecko浏览器提供了与旧版浏览器不同的页面。 KHTML最初是为Linux的KDE桌面上的Konquerer开发的,添加了“ like Gecko”一词,因此他们也可以获得专为Gecko设计的现代页面。 WebKit基于KHTML –在开发时,他们添加了WebKit一词,并保留了原始的“ KHTML,如Gecko”这一行,以实现兼容性。 这样,浏览器开发人员就不断在其用户代理中添加单词。

Web servers don’t really care what the exact user agent string is – they just check to see if it contains a specific word.

Web服务器实际上并不关心确切的用户代理字符串是什么,它们只是检查它是否包含特定的单词。

用途 (Uses)

Web servers use user agents for a variety of purposes, including:

Web服务器将用户代理用于多种目的,包括:

  • Serving different web pages to different web browsers. This can be used for good – for example, to serve simpler web pages to older browsers – or evil – for example, to display a “This web page must be viewed in Internet Explorer” message.将不同的网页提供给不同的Web浏览器。 这可能有益(例如,将较简单的网页提供给较旧的浏览器),也可能有害(例如,用于显示“必须在Internet Explorer中查看此网页”)消息。
  • Displaying different content to different operating systems – for example, by displaying a slimmed-down page on mobile devices.向不同的操作系统显示不同的内容-例如,通过在移动设备上显示缩小的页面。
  • Gathering statistics showing the browsers and operating systems in use by their users. If you ever see browser market-share statistics, this is how they’re acquired.收集统计信息,显示其用户正在使用的浏览器和操作系统。 如果您看到过浏览器市场份额的统计数据,这就是它们的获取方式。

Web-crawling bots use user agents, too. For example, Google’s web crawler identifies itself as:

爬网机器人也使用用户代理。 例如,Google的网络爬虫将自己标识为:

Googlebot/2.1 (+http://www.google.com/bot.html)

Googlebot / 2.1(+ http://www.google.com/bot.html)

Web servers can give bots special treatment – for example, by allowing them through mandatory registration screens. (Yes, this means that you can sometimes bypass registration screens by setting your user agent to Googlebot.)

Web服务器可以给漫游器以特殊待遇,例如,允许它们通过强制注册屏幕。 (是的,这意味着您有时可以通过将用户代理设置为Googlebot来绕过注册屏幕。)

Web servers can also give orders to specific bots (or all bots) using the robots.txt file. For example a web server could tell a specific bot to go away, or tell another bot to only index certain areas of the website. In the robots.txt file, the bots are identified by their user agent strings.

Web服务器还可以使用robots.txt文件向特定的机器人(或所有机器人)下达命令。 例如,Web服务器可以告诉某个特定的漫游器消失,或者告诉另一个漫游器仅对网站的某些区域编制索引。 在robots.txt文件中,漫游器由其用户代理字符串标识。



All major browsers contain ways to set custom user agents, so you can see what web servers send to to different browsers. For example, set your desktop browser to a mobile browser’s user agent string and you’ll see the mobile versions of web pages on your desktop.

所有主要的浏览器都包含设置自定义用户代理的方法,因此您可以查看Web服务器发送到不同浏览器的内容。 例如,将桌面浏览器设置为移动浏览器的用户代理字符串,您将在桌面上看到网页的移动版本。

翻译自: https://www.howtogeek.com/114937/htg-explains-whats-a-browser-user-agent/

浏览器用户代理

浏览器用户代理_什么是浏览器的用户代理?相关推荐

  1. 浏览器兼容_查成绩浏览器不兼容怎么办?

    2020教资交流群 (扫码进群) 加群及时了解考试动态.免费备考资料 今晚19:00,面试报名指导及复习计划? 问题:教师资格证查询不是IE6-IE10系列浏览器,怎么办? 答:由于系统兼容性不足,所 ...

  2. serversocket 返回浏览器图片_深入理解浏览器的缓存机制

       戳蓝字「前端技术优选」关注我们哦! 一.前言 缓存可以说是性能优化中简单高效的一种优化方式了.一个优秀的缓存策略可以缩短网页请求资源的距离,减少延迟,并且由于缓存文件可以重复利用,还可以减少带宽 ...

  3. delphi 调用浏览器内核_深入理解浏览器原理

    导语:本文从市面主流的浏览器及相应的内核引擎开始,介绍了Chromium为代表的浏览器架构及Blink内核的功能架构.Chromium为多进程架构,用户从启动运行浏览器后,先后经过页面导航.渲染.资源 ...

  4. java浏览器内核_深入理解浏览器内核 - 概述

    欢迎点击「算法与编程之美」↑关注我们! 本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章. 继"汉芯"事件造假之后,近期"红 ...

  5. 浏览器体系结构_了解代理浏览器:体系结构

    浏览器体系结构 I did a bunch of research on proxy-browsers for a few projects I worked on. Rather than sitt ...

  6. chrome浏览器缓慢_缓慢的浏览器? 这是加快Chrome浏览器速度的方法

    chrome浏览器缓慢 Does your Chrome browser feel like it's running a bit slower than usual? These tips and ...

  7. cas 注销不关闭浏览器异常_一次浏览器请求的生命周期

    " 我们经常使用浏览器访问各种资源,那在浏览器输入一个地址,究竟做了哪些事情呢?OSI七层协议有什么作用呢?HTTP协议请求体和返回体有哪些参数需要注意呢?"01-浏览器请求-生命 ...

  8. 浏览器崩溃_如何在浏览器不崩溃的情况下过滤200万行数据?

    作者|Bruno Couriol 编辑|无明 最近我分配到了一个非常有趣的任务:在前端显示 1GB 文件和 200 万行数据,并实现过滤,在这篇文章中,我将分享我是如何完成这个任务的. 背景 我曾经创 ...

  9. 浏览器登录_经常用浏览器自动登录忘记了密码?教你一键查看网页星号密码

    不知道大家有没有出现这种情况,因为一直用的网页自动填写密码来登录,所以有时候甚至把密码给忘了 相信有的小伙伴有可能就会出现这种情况哈,今天小林君来教你个超简单的方法,不用安装任何软件,就可以一键查看网 ...

最新文章

  1. 计算机应用基础试题及答案试卷号7074,阅读文章,完成试题。后来才知道,在这千钧一发的时刻,是郝副营长划着了火柴,点燃了那本书,举得高高的, - 学进去中小学试卷试题库...
  2. 如何在Ruby中写入文件?
  3. ExtJs Ext.panel.Panel和Ext.container.Viewport布局问题
  4. JUC多线程:CountDownLatch、CyclicBarrier、Semaphore同步器原理总结
  5. 4进程原语:fork()函数,getpid()函数和getppid()函数,getuid()函数,getgid()函数,vfork()
  6. 使用SAPGUI画图
  7. latex绘图笔记(一)
  8. 如何优雅地实现判断一个值是否在一个集合中?
  9. 安卓“新皇”来了!华为Mate 40确定10月22日发布
  10. 【机器学习-西瓜书】三、线性回归;对数线性回归
  11. 辽宁职称计算机和英语考试,2018年辽宁职称计算机报考有哪些要求?
  12. ESP32学习笔记(12)——JSON接口使用
  13. Luarocks 安装艰难过程
  14. 打开ISEIP核里面的datesheet失败,显示C:\Program Files (x86) internet explorer\iexplore.exe http:\\www.xilinx.com
  15. Android应用中打开百度地图、高德地图、网页版百度地图
  16. Mac小白——如何查看网速
  17. se78 上传图片(logo使用)/SWM0上传文件
  18. 2020.4.11普及C组 Loan Repayment【纪中】【二分】
  19. 02 【uni-app起步】
  20. 2020年十大OA办公系统排行榜

热门文章

  1. 如何用SVG做出背景填充效果 avatar
  2. MongoDB深究之ObjectId
  3. android 模糊drawable,Android ShapeDrawable笔画模糊
  4. 让淘宝败诉,令携程吃瘪!这群把你气到炸的人,是巨头们最恐惧的天敌
  5. 北航教授多旋翼无人机教程
  6. 三级省市联动菜单的js源码
  7. js判断是否是数字简单方法
  8. python开发板推荐_Python玩转单片机:从基础到进阶,几款主流的开发板大盘点!...
  9. 古代时间算法 + 生肖对应顺序
  10. 简单Cookie应用Demo