使用response.sendRedirect方法在java中发送Post请求 [英] Send Post request in java with response.sendRedirect method

查看:5831
本文介绍了使用response.sendRedirect方法在java中发送Post请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java中发送一个帖子请求。
我已经看到了使用Http Client发布请求的示例。
但是我想使用sendRedirect方法。

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.

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


推荐答案

根据RFC2616用HTTP / 1.1你可以发送307响应代码,它将使用户代理重复它对提供主机的POST请求。
在您的情况下,只需执行

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

响应是您的HttpServletResponse对象。

response is your HttpServletResponse object.

希望这会有所帮助。

这篇关于使用response.sendRedirect方法在java中发送Post请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆