【发布时间】:2016-02-09 19:20:24
【问题描述】:
我使用 Apache Httpclient 通过代理打开 URL 并获得响应,而不是我想从传递 post 参数的代理重定向站点。 这是我的代码,它是一个 servlet
String parameter= request.getParameter("parameter");
HttpClient httpClient = new HttpClient();
httpClient.getHostConfiguration().setProxy(proxyhost, proxyport);
log.info("message:::"+message);
PostMethod postMethod = new PostMethod(url);
NameValuePair[] data = new NameValuePair[1];
data[0] = new NameValuePair("parameter", parameter);
postMethod.setRequestBody(data);
int code = httpClient.executeMethod(postMethod);
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.print(postMethod.getResponseBodyAsString());
实际问题是正在从其他站点获得响应,并且正在呈现 html 并单击浏览器中的链接,正在从我的服务器打开 URL,因为响应来自这种格式 var url "../../someparams" 它确实应该打开http://url/someparams(url 这里在上面的代码中提到过)或者一旦使用代理点击 URL,我们也可以在浏览器中重定向到该页面我的意思是通过该代理打开 URL 并删除被调用的 servlet。
@法律安东尼: response.sendRedirect("http://www.google.com");没有帮助
需要您的帮助来解决这个问题。
【问题讨论】:
-
怎么解决不了问题?
标签: java proxy apache-httpclient-4.x