在与第三方系统对接,我们提供一个接口链接给第三方做回传通知调用,如果不知道对方的请求方式,请求参数,请求体的时候,
我们需要一些手段来获取这些信息。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26@RequestMapping(value = "notify") @ApiOperation(value = "接收支付通知消息", notes = "") public R receviceNotifyMsg() throws Exception{ HttpServletRequest request= ServletUtils.getRequest(); //获取请求参数集 String parametermap=JSON.toJSONString(request.getParameterMap()); logger.info("method:{},parametermap:{},contentType:{}",request.getMethod(),parametermap, request.getContentType()); try { logger.info("receivePost:{}", receivePost( request)); }catch (Exception e){ e.printStackTrace(); } return R.ok("通知消息接收成功!"); } public static String receivePost(HttpServletRequest request) throws IOException, UnsupportedEncodingException { // 读取请求内容 BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); String line = null; StringBuilder sb = new StringBuilder(); while((line = br.readLine())!=null){ sb.append(line); } // 将资料解码 String reqBody = sb.toString(); return URLDecoder.decode(reqBody, HTTP.UTF_8); }
最后
以上就是眼睛大牛排最近收集整理的关于Java Request 获取请求method,请求param,请求body的全部内容,更多相关Java内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复