Send Post request in java with response.sendRedirect method

http-post, java

Solution

According to RFC2616 with HTTP/1.1 you can send 307 response code, which will make `user-agent` to repeat it's POST request to provided host. In your case just do

response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
response.setHeader("Location", url);

response is your `HttpServletResponse` object.

Hope this helps.

Problem

I want to send a post request in java. I have seen examples for the post request by using Http Client. But i want use sendRedirect method. For ex, https://processthis.com/process?name=xyz&phone=9898989898 I want to use post request to send those parameters. So, those params will not be visible to any one and at the same time i need to redirect my url to that url as, ``` response.sendRedirect("https://processthis.com/process"); ```

Original source