springmvc从stream中获取参数,加idea测试

背景:直接接收流数据,直接输出流数据

@RestController
@Slf4j
public class HelloController {


    @PostMapping(value = "/hello",produces = "application/json")
    public void hello(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String encoding = request.getCharacterEncoding();
     // 从流中获取数据 String body
= StreamUtils.copyToString(request.getInputStream(), Charset.forName(encoding)); log.info("log : {} ",body); String resp="<html><head>i am head</head><body>i am body <body></html>";
    // 将数据写入输出流中 response.getOutputStream().write(resp.getBytes()); }

idea插件测试接口,类似postman功能

位置:tools--> http client --> test restful web service

 (愿idea越发强大)

原文地址:https://www.cnblogs.com/windy13/p/12782924.html