如果我们把请求参数如果放在HttpPost或者HttpGet中后端该如何取参?
有两种方式
一种是从请求数据流中获取数据 ```java @AnonymousPostMapping("/api/router") public RestResult router(HttpServletRequest requestEntity) throws Exception { String inputStream = getInputStream(requestEntity); // Object requestEntityBody = requestEntity.getBody(); System.out.println(123); return RestResult.success(); } ``` ```java public static String getInputStream(HttpServletRequest request) throws Exception { ServletInputStream stream = null; BufferedReader reader = null; StringBuffer sb = new StringBuffer(); try { stream = request.getInputStream(); // 获取响应 reader = new BufferedReader(new InputStreamReader(stream)); String line; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (IOException e) { // logger.error(e); } finally { reader.close(); } return sb.toString(); } ``` 方式二: 如果用的是springboot框架 可以用自带的 RequestEntity 作为实体进行接收 包是:package org.springframework.http;
```java @AnonymousPostMapping("/api/router") public RestResult router(RequestEntity requestEntity) throws IOException { Object requestEntityBody = requestEntity.getBody(); System.out.println(123); return RestResult.success(); } ```
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有