首页 文章 精选 留言 我的

精选列表

搜索[全能手机连接助手],共10000篇文章
优秀的个人博客,低调大师

区分不同手机平台客户端

Conclusion:Unlike User-Agent ,which let the browser describe its meta data and information , the two kinds of client by default will not have a pre-defined field which can function like this. Solution:(We created aself-defined fieldin the http header) For example ,we create a field namedMobile-Agent In client side: when we construct the http request ,we add the value of header “Mobile-Agent” to be some value Android Client codeonly need to set the “Mobile-Agent” header to be ”Android”. Code example: (see myhighlighted) publicJSONObjectcallJSONWebService(Stringurl){ HttpParamsmy_httpParams=newBasicHttpParams(); HttpConnectionParams.setConnectionTimeout(my_httpParams,conn_timeout); HttpConnectionParams.setSoTimeout(my_httpParams,conn_timeout); HttpClienthttpClient=newDefaultHttpClient(my_httpParams); HttpGethttpRequest=newHttpGet(url); httpRequest.setHeader("User-Agent","bleumagent"); httpRequest.setHeader(“Mobile-Agent”,”Android”); HttpResponsehttpResponse=null; JSONObjecthttpJsonResult=null; Stringresult=null; try{ httpResponse=httpClient.execute(httpRequest); if(httpResponse.getStatusLine().getStatusCode()==200){ HttpEntityhttpEntity=httpResponse.getEntity(); if(httpEntity!=null){ InputStreaminputStream=httpEntity.getContent(); result=this.convertStreamToString(inputStream); httpJsonResult=newJSONObject(result); inputStream.close(); } } }catch(Exceptione){ System.out.println("callJsonWebServicefailed."); e.printStackTrace(); } httpClient.getConnectionManager().shutdown(); returnhttpJsonResult; } IPhoneClient codecan use Objective-C to do the similar thing ,just set the “Mobile-Agent” header to be “IPhone” In server side’s servlet : we only use the Servlet API to resolve “Mobile-Agent” field. Then solved. 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/835904,如需转载请自行联系原作者

优秀的个人博客,低调大师

JavaScript-手机中访问页面判断

最近在做微信服务号开发,其中遇到一个问题是微信服务号查看的个人的消息,如果点击在浏览器中查看(iOS中是在Safari中打开)应该是跳转到登录页面,因为页面需要从后台获取,因为需要服务端判断,如果是存页面不需要后台数据可以在前台进行判断,因为后台是NodeJS,所以给出客户端和服务端两个版本的代码供参考。 客户端判断 方法很简单,就是通过userAgent去判断,先判断是否为移动端,可以判断是iOS终端和Android终端,也可以具体到应用进行判断微信,微博,qq访问: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 var browser = { versions: function() { var u = navigator.userAgent, ua = navigator.userAgent.toLowerCase(); return { //移动终端浏览器版本信息 trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1, //是否iPad webApp: u.indexOf('Safari') == -1 ,//是否web应该程序,没有头部与底部 wechat:ua.match(/MicroMessenger/i) == "micromessenger",//微信 weibo:ua.match(/WeiBo/i) == "weibo",//微博 qq:ua.match(/QQ/i) == "qq"//qq }; }(), language: (navigator.browserLanguage || navigator.language).toLowerCase() }; console.log(navigator.userAgent); 服务端判断 NodeJS同样也是通过userAgent判断,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 var browser= function(req) { var u = req.headers['user-agent']; var ua = u.toLowerCase(); //移动终端浏览器版本信息 return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1, //是否iPad webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部 wechat: ua.match(/MicroMessenger/i) == "micromessenger",//微信 weibo: ua.match(/WeiBo/i) == "weibo",//微博 qq: ua.match(/QQ/i) == "qq"//QQ空间 }; }; exports.browser=browser; 基本的判断都有,可以根据判断的结果给出不同的响应~ 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/5013028.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册