/** * servletutil */ public String getParentCode() throws IOException { /*RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes1 = (ServletRequestAttributes) attributes; String parentCode = attributes1.getRequest().getParameter("parentCode");*/ HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder .getRequestAttributes()).getRequest(); String parentCode1 = request.getParameter("parentCode"); System.out.println("请求头中信息"); Enumeration<String> headerNames = request.getHeaderNames(); while(headerNames.hasMoreElements()){ String key = headerNames.nextElement(); String value = request.getHeader(key); System.out.println(key + " " +value); } System.out.println("url中拼接的数据"); //从request中拿url中拼接的参数 Map<String, String[]> map = request.getParameterMap(); for (String s: map.keySet()) { System.out.print(s + "===>"); for (int i = 0; i < map.get(s).length; i++) { System.out.print(map.get(s)[i].toString() + " "); } System.out.println(); }; System.out.println("post请求中请求体数据"); //post请求中请求体数据 StringBuffer data = new StringBuffer(); String line = null; BufferedReader reader = null; try { reader = request.getReader(); while (null != (line = reader.readLine())) data.append(line); } catch (IOException e) { } finally { reader.close(); } System.out.println(data.toString()); return headerNames.toString(); }
获取request请求的请求头、url、请求体(post)、中的数据
最新推荐文章于 2024-03-06 09:02:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)