[英]intercepting http post using httpservletrequest
I'm going to redirect http post request to another server (just changing url and some headers) and using a Servlet for this purpose. 我将把http post请求重定向到另一台服务器(只是更改url和一些标头),并为此使用Servlet。 In Servlet, i'm using HttpClient to send request and get response.
在Servlet中,我使用HttpClient发送请求并获取响应。 The question is: would these operations send the whole post request to the target?
问题是:这些操作是否会将整个发帖请求发送给目标? :
:
copy httpServletRequest headers into httpClient request 将httpServletRequest标头复制到httpClient请求中
and then put httpServletRequest#inputStream in request entity like this: 然后将httpServletRequest#inputStream放在请求实体中,如下所示:
HttpEntity entity = new InputStreamEntity(httpServletRequest.getInputStream(), someContentType); HttpEntity实体= new InputStreamEntity(httpServletRequest.getInputStream(),someContentType);
I mean is the request = headers + input stream? 我的意思是请求=标头+输入流? if not, what else should be copied?
如果没有,还应该复制什么?
Just to be on same page regarding terminology: 关于术语只是在同一页上:
if you want to add headers to the request, redirect is not an option afaik. 如果要向请求添加标头,则重定向不是afaik选项。 if you want to forward to another external url, forwarding is not an option.
如果要转发到另一个外部URL,则不能选择转发。
so, you need to do a new http request to the other site as part of your original request processing. 因此,作为原始请求处理的一部分,您需要向另一个站点发出新的http请求。 but you must process that original request to extract whatever info you need (not trying to reuse inputstream).
但是您必须处理该原始请求以提取所需的任何信息(不要尝试重用inputstream)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.