如何从servlet请求到另一台服务器

问题描述:

我想从我的servlet发送请求到另一台服务器,并获得响应在同一个servlet中。例如:请求:如何从servlet请求到另一台服务器

http://www.anotherserver.com?para=pValue  

被发送给其他服务器,并获取它发送的响应,然后处理响应。请给我一个示例代码。

+0

10您是否看过RequestDispacther? – Dimitri 2012-03-27 15:36:32

+0

有没有办法检索其他服务器在RequestDispatcher中发送的响应? – 2012-03-27 15:46:07

您可以在Java代码中使用Apache HttpClient(http://hc.apache.org/httpcomponents-client-ga/index.html)进行HTTP调用。

示例:http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java

+0

谢谢。但我怎样才能找到直接的答案。你会更具体吗? – 2012-03-27 15:31:59

+0

请参阅上面链接中的示例代码。 – 2012-03-27 15:37:02

+0

非常感谢。有效 :) – 2012-03-27 17:07:39