在将请求发送到 Java 中的其他位置之前,向请求添加 post 参数
在 JSP 页面中,我需要执行以下操作(这是伪代码):
//Attach new POST params to request
//Make the request go to a 3rd party URL
我该如何执行此操作?
我们现在解决这个问题的方法(很糟糕):
//populate and generate an HTML form
//on window.load submit the HTML form (as a POST) to a 3rd party URL
我们希望所有这些都在服务器端完成,而不是使用这种 JS hack
In a JSP page, I need to do the following (this is psuedo-code):
//Attach new POST params to request
//Make the request go to a 3rd party URL
How do I do this?
The way we are solving this right now (is terrible):
//populate and generate an HTML form
//on window.load submit the HTML form (as a POST) to a 3rd party URL
We want all this to be done on the server side instead of having this JS hack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
URLConnection
发出POST
请求,此处是一个例子You can use
URLConnection
to makePOST
request, here is an example发送 HTTP POST 的方法有很多种。我推荐使用 apache
HttpClient
库。以下是之前关于 Stack Overflow 的问题和解答。问题是针对 Andriod 的,但应该可以与 Java 完美配合。
另一种方法是使用
URLConnection
类。我就这个问题发布了一个答案。There are many ways to send a HTTP POST. I recommend a use of apache
HttpClient
library.Here is the previous question and answers on Stack Overflow. The question was for Andriod but should work perfectly with Java.
Another method is to use
URLConnection
class. There was an answer posted by me on that question.在 Java 中没有办法做到这一点。您需要某种代理服务器或 apache 重写规则或类似的东西。 Java 不是执行此操作的正确位置。
There is no way to do this in Java. You would need some sort of proxy server or apache re-write rule or something like that. Java is not the right place to do this.