简体   繁体   English

无法从标题正确获取“ User-Agent”

[英]Unable to get `User-Agent` properly from header

`Hi, 嗨,

I am trying to get the user's browser information in my servlet filter. 我试图在我的servlet过滤器中获取用户的浏览器信息。 I used a simple code, see below. 我使用了一个简单的代码,请参见下文。

String userAgent = request.getHeader("User-Agent");

User was using Google chrome, and what the above code printed is below. 用户正在使用Google chrome,上面打印的代码如下。

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

It printed the names of all the major browsers instead of getting the once the app is running. 它会打印所有主要浏览器的名称,而不是在应用程序运行后立即显示。 what is wrong here? 这是怎么了

Nothing is wrong here. 这里没事。

For example let us consider the returned string is 例如,让我们考虑返回的字符串是

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 41.0.2228.0 Safari / 537.36

Then the explanation is 然后的解释是

ChromeChrome 41.0.2228.0

Mozilla ==> 

MozillaProductSlice. Claims to be a Mozilla based user agent, which is only true for Gecko browsers like Firefox and Netscape. For all other user agents it means 'Mozilla-compatible'. In modern browsers, this is only used for historical reasons. It has no real meaning anymore

5.0 ==> Mozilla version

Windows NT 6.1  ==> Operating System Windows 7 

AppleWebKit  ==> The Web Kit provides a set of core classes to display web content in windows

537.36       ==> Web Kit build
KHTML        ==> Open Source HTML layout engine developed by the KDE project
like Gecko   ==> like Gecko...
Chrome  Name ==> Chrome
41.0.2228.0  ==> Chrome version
Safari       ==> Based on Safari
537.36       ==> Safari build

Description:    Free open-source web browser developed by Google. 
Chromium is the name of the open source project behind Google Chrome, released under the BSD license.

You can find more information in below link 您可以在下面的链接中找到更多信息

http://www.useragentstring.com/pages/Chrome/ http://www.useragentstring.com/pages/Chrome/

click on each link on the page to get more info 单击页面上的每个链接以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从用户请求中获取用户代理? - How can I get a User-agent from user request? 如何在Vaadin中设置用户代理标头? - How to set user-agent header in Vaadin? 在https连接头中设置user-agent属性 - Set user-agent property in https connection header 将HTTP标头“ User-Agent”添加到HTTP CONNECT请求 - Add http header “User-Agent” to HTTP CONNECT request 如何从 Webview 的页面内部获取 json 响应(我收到用户代理的响应)? - How to get json response from inside the page from Webview(I get a response with user-agent)? 即使在包含 User-Agent 属性后,从 java 对网站的 GET 请求也会返回 403 - GET request to website from java returns 403 even after including User-Agent property 谁能帮助您以编程方式使用Selenium Webdriver将修改标头用户代理添加到Chrome浏览器 - Can anyone help to how to add modify header user-agent to chrome browser using selenium webdriver programmatically 如何防止用户更改用户代理 - How to prevent user-agent to be changed by user Appengine欺骗用户代理字符串 - Appengine spoof User-Agent string 过滤器之前的资源中没有用户代理(getAgent) - No user-agent (getAgent) in filter preceding resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM