简体   繁体   English

如何使用HttpURLConnection发送HttpRequest?

[英]How to send a HttpRequest using HttpURLConnection?

I have a proxy server (JAX-RS) and I want to forward some request to an other server. 我有一个代理服务器(JAX-RS),我想将一些请求转发到另一台服务器。 I can do that, with getting the original Request, get all headers and data from it, and one-by-one set the HttpURLConnection, but it's not efficient I think. 我可以通过获取原始Request来做到这一点,从中获取所有标头和数据,并一一设置HttpURLConnection,但是我认为这样做效率不高。

Is there a way to 有没有办法

  • just forward the request 只是转发请求

OR 要么

  • "clone" the request , send it to the other server, and then send back the client the response “克隆”请求 ,将其发送到其他服务器,然后将响应发送回客户端

RequestDispatcher.forward(request)或sendredirect()方法有什么问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM