解析客户端请求信息Headers

[b]ANDROID客户端请求[/b]

{Accept=[application/json], accept-encoding=[gzip,deflate], accept-language=[zh-CN,en-US;q=0.8], connection=[keep-alive], Content-Length=[51], content-type=[application/json;charset=UTF-8], host=[10.254***:8888], origin=[http://www.***.cn], referer=[http://www.***.cn/***/index.html?showAcitivityIcon=0], user-agent=[Mozilla/5.0 (Linux; Android 4.4.2; PE-TL20 Build/Huawei***) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36], x-requested-with=[com.***], x-wap-profile=[http://wap1.huawei.com/uaprof/HUAWEI_***_UAProfile.xml]}

[b]IOS客户端请求[/b]

{Accept=[application/json], accept-encoding=[gzip, deflate], accept-language=[zh-Hans-CN;q=1], connection=[close], Content-Length=[68], content-type=[application/json], host=[www.***.cn], user-agent=[***/2.5.0 (iPhone; iOS 10.0.2; Scale/2.00)], x-forwarded-for=[10.254***], x-real-ip=[10.254***]}

[b]解析Headers[/b]


public String getHeaders(HttpServletRequest request,String type){
String flag="";
Map<String, String> map=new HashMap<String, String>();
Enumeration<String> headers=request.getHeaderNames();
while (headers.hasMoreElements()) {
String key=(String) headers.nextElement();
String value=request.getHeader(key);
map.put(key, value);
System.out.println("输出key:"+key);
}
if(!map.isEmpty()){
flag=map.get(type);
if(Utils.isNotBlank(flag)){
if(flag.toUpperCase().contains(Enum.DEVICE_TYPE_ANDROID.getCode())){
flag=Enum.DEVICE_TYPE_ANDROID.getCode();
}else if(flag.toUpperCase().contains(Enum.DEVICE_TYPE_IOS.getCode())){
flag=Enum.DEVICE_TYPE_IOS.getCode();
}else{
flag=Enum.DEVICE_TYPE_UNKNOWN.getCode();
}
}
}
System.out.println("结果:"+flag);
return flag;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值