如何检测请求是来自浏览器还是智能手机? [英] how to detect whether request is coming from browser or smartphone?

查看:355
本文介绍了如何检测请求是来自浏览器还是智能手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web应用程序,它运行正常。
现在有一个特定的页面,当我从智能手机浏览器访问应用程序时变得笨重,所以我想要一个像

I am having a web application , which works fine . now there is a particular page which gets bulky when i access the application from smartphone browser , so I wanted a situation like

if(request comes from computer browser client )
forward to bulky page in web application
else
if (request comes from smartphone )
forward to some other light page .

请提出你的建议我如何实现这个

please put your suggestion how can i achieve this

推荐答案

使用用户代理。根据方便和惯例,与服务器的每个连接都带有此标头。无法保证浏览器是真实的(例如spambot将自己报告为Chrome)。您可以按如下方式获取用户代理:

Use the user-agent. Every connection to your server carries this header, by convenience and convention. There is no guarantee that a browser will be truthful(such as a spambot reporting itself as Chrome). You can get the user-agent as follows:

request.getHeader("User-Agent");

然后再次检查已知的用户代理字符串和模板。

and then check again known user-agent strings and templates.

这篇关于如何检测请求是来自浏览器还是智能手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆