java 后台发送post,使用response.sendRedirect方法在java中发送Post请求

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.

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");

解决方案

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.