private Map<String, String> getHeadersInfo(HttpServletRequest request) {
Map<String, String> map = new HashMap<String, String>();
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);
//System.out.println(key+":"+value);
}
return map;
}
Map<String,String> map = getHeadersInfo(request);
String userAgent = map.get("user-agent");
String referer = map.get("referer");
System.out.println("userAgent"+userAgent+":referer"+referer);
public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
}
private String getCookieId(HttpServletRequest request){
Cookie[] cookie = request.getCookies();
for (int i = 0; i < cookie.length; i++) {
Cookie cook = cookie[i];
System.out.println(cook.toString());
if(cook.getName().equalsIgnoreCase("eredg4.login.account")){ //获取键
System.out.println("account:"+cook.getValue().toString()); //获取值
}
}
return "";
}

-HeadersInfo-host:localhost:8080
-HeadersInfo-connection:keep-alive
-HeadersInfo-content-length:6
-HeadersInfo-origin:http://localhost:8080
-HeadersInfo-x-requested-with:XMLHttpRequest
-HeadersInfo-user-agent:Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36
-HeadersInfo-content-type:application/x-www-form-urlencoded
-HeadersInfo-accept:*/*
-HeadersInfo-referer:http://localhost:8080/index.html
-HeadersInfo-accept-encoding:gzip, deflate
-HeadersInfo-accept-language:zh-CN,zh;q=0.8
http://www.cnblogs.com/icerainsoft/p/3584532.html

request获取各种信息的更多相关文章

  1. jsp Request获取url信息的各种方法比较

    从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...

  2. 微信小程序获取用户信息

    App({ appData: { userInfo:{ user_portraitUrl: "", user_nick: "", user_gender: 0, ...

  3. thinkphp5.0 获取请求信息

    如果要获取当前的请求信息,可以使用\think\Request类,除了下文中的 $request = Request::instance(); 也可以使用助手函数 $request = request ...

  4. request 获取请求头

    /********************************************************servlet页面********************************** ...

  5. Request获取url各种信息的方法

    1.Request获取url各种信息的方法 测试的url地址:http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPa ...

  6. 微信快速开发框架(八)-- V2.3--增加语音识别及网页获取用户信息,代码已更新至Github

    不知不觉,版本以每周更新一次的脚步进行着,接下来应该是重构我的代码及框架的结构,有朋友反应代码有点乱,确实如此,当时写的时候只是按照订阅号来写的,后来才慢慢增加到支持API接口.目前还在开发第三方微信 ...

  7. 内网公告牌获取天气信息解决方案(C# WebForm)

    需求:内网公告牌能够正确显示未来三天的天气信息 本文关键字:C#/WebForm/Web定时任务/Ajax跨域 规划: 1.天定时读取百度接口获取天气信息并存储至Txt文档: 2.示牌开启时请求Web ...

  8. .NET获取服务器信息,如服务器版本、IIS等

    .NET获取服务器信息,如服务器版本.IIS等 .NET获取服务器信息,如服务器版本.IIS版本.数据库大小.网站系统空间占用大小.网站部署路径等等 .NET获取系统环境信息 #region 返回操作 ...

  9. C# HttpWebRequest 绝技 根据URL地址获取网页信息

    如果要使用中间的方法的话,可以访问我的帮助类完全免费开源:C# HttpHelper,帮助类,真正的Httprequest请求时无视编码,无视证书,无视Cookie,网页抓取 1.第一招,根据URL地 ...

随机推荐

  1. schtasks在win7下提示错误:无法加载列资源

    转自: http://blog.chinaunix.net/uid-24946452-id-2887851.html 查看cmd 编码 chcp 如使用 936中文GBK编码的话 schtasks.e ...

  2. java 使用 poi 解析excel

    背景: web应用经常需要上传文件,有时候需要解析出excel中的数据,如果excel的格式没有问题,那就可以直接解析数据入库. 工具选择: 目前jxl和poi可以解析excel,jxl很早就停止维护 ...

  3. C# 遍历类的属性并取出值

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷 学无止境,精益求精    今天有点胡思乱想,想遍历MVC Model的属性并 ...

  4. 将数据文件从asm移到普通文件系统

    数据库可以关闭的场景: 1.关闭并重新mount数据库 $ sqlplus '/as sysdba' SQL> shutdown immediate; SQL> startup mount ...

  5. replace截取字段

    var a = '123:'b = '123:disfkajsdhfjkasdhf'c = b.replace(a, '')"disfkajsdhfjkasdhf"

  6. 学习OpenCV——绘制彩色直方图(HSV2BGR)

    #include <cv.h> #include <highgui.h> #include <iostream> using namespace std; int ...

  7. JDBC增删改查,PreparedStatement和Statement的区别

    此篇是在上一篇的基础上使用PreparedStatement对象来实现JDBC增删改查的 具体工具类JDBCTools和实现类和配置文件在上一篇Statement对象实现的时候有写. 上一篇地址htt ...

  8. c# winForm使用Aspose.Cells读取CSV文件中文乱码问题

    不废话直接上代码 主要注意是 红色代码部分 Aspose.Cells.TxtLoadOptions lo = new TxtLoadOptions();                      lo ...

  9. mongo基本语句

    批量更新 db.test.updateMany({name:'test'},{$set:{value:1}}) 单更新 db.test.update({name:'test'},{$set:{valu ...

  10. Yii2.0中文开发向导——Where条件查询全解析

    在Yii的Model里进行查询的时候 where是必不可少的.Where方法声明为 static where( $condition ) 其中参数 $condition类型为字符串或者数组 1.字符串 ...