打印request的信息
HttpServletRequest req = (HttpServletRequest) RequestContext.getCurrentContext().getRequest(); System.err.println("REQUEST:: " + req.getScheme() + " " + req.getRemoteAddr() + ":" + req.getRemotePort()); StringBuilder params = new StringBuilder("?"); // 获取URL参数 Enumeration<String> names = req.getParameterNames(); if (req.getMethod().equals("GET")) { while (names.hasMoreElements()) { String name = (String) names.nextElement(); params.append(name); params.append("="); params.append(req.getParameter(name)); params.append("&"); } } if (params.length() > 0) { params.delete(params.length() - 1, params.length()); } System.err.println( "REQUEST:: > " + req.getMethod() + " " + req.getRequestURI() + params + " " + req.getProtocol()); Enumeration<String> headers = req.getHeaderNames(); while (headers.hasMoreElements()) { String name = (String) headers.nextElement(); String value = req.getHeader(name); System.err.println("REQUEST:: > " + name + ":" + value); } RequestContext ctx = RequestContext.getCurrentContext(); if (!ctx.isChunkedRequestBody()) { ServletInputStream inp = null; try { inp = ctx.getRequest().getInputStream(); String body = null; if (inp != null) { body = IOUtils.toString(inp); System.err.println("REQUEST:: > " + body); } } catch (IOException e) { e.printStackTrace(); } }
转http://c.biancheng.net/view/5424.html
本文作者:___mouM
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。
版权说明:本文版权归作者和博客园共有,欢迎转载。但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.