如何使用Apache Http组件从servlet中继POST请求?

时间:2022-04-19 18:12:56

I'm a little unfamiliar both with the Servlet API and Apache Http Components.

我对Servlet API和Apache Http组件都不太熟悉。

I need to handle an incoming POST request with unknown data (although probably the result of a form submission) using HttpServlet.doPost() which I've implemented, and request the same posted information from another URL, effectively acting as a relay for the HTTP POST. I then need to convert the response to a String (it will be text/html) and process it further before returning it to the web browser that requested it from me.

我需要使用我实现的HttpServlet.doPost()处理带有未知数据的传入POST请求(尽管可能是表单提交的结果),并从另一个URL请求相同的发布信息,有效地充当了HTTP POST。然后我需要将响应转换为String(它将是text / html)并进一步处理它,然后将其返回到我请求它的Web浏览器。

Due to my unfamiliarity with these libraries, its not clear to me how to handle issues like the content-type of the posted data, and also avoiding any problems due to neglecting to release resources.

由于我对这些库不熟悉,我不清楚如何处理发布数据的内容类型等问题,也避免因忽略释放资源而导致的任何问题。

Can anyone provide any pointers on this?

任何人都可以提供任何指针吗?

1 个解决方案

#1


0  

You should start by having a look at HttpClient class from apache API. It will handle both get and posts as needed and later you could feel its request with the data you receive in your own servlet.

您应该首先从apache API查看HttpClient类。它将根据需要处理get和posts,之后您可以使用您自己的servlet中收到的数据来感受它的请求。

#1


0  

You should start by having a look at HttpClient class from apache API. It will handle both get and posts as needed and later you could feel its request with the data you receive in your own servlet.

您应该首先从apache API查看HttpClient类。它将根据需要处理get和posts,之后您可以使用您自己的servlet中收到的数据来感受它的请求。