When ever I try to get the request body inside the springboot filter (in order to check some parameters) a BAD request error is thrown
Here's the code for the filter
public class PostURLFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
InputStream requestInputStream = req.getInputStream();
try {
String body = StreamUtils.copyToString(requestInputStream, StandardCharsets.UTF_8);
out.println(body + "this is the body");
} catch (Exception e) {
out.println(e);
}
out.println("end");
filterChain.doFilter(servletRequest, servletResponse);
}
}
This is my POST request body
{
"id":590,
"name":"run"
}
Without this piece of code (requesting the request body) the POST request works fine. But with this it doesn't run.
I don't know where I'm missing the login. Kindly help me. Thanks in advance!