【问题标题】:How to redirect to a site from proxy java如何从代理 java 重定向到站点
【发布时间】: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


【解决方案1】:

这是一个servlet吗? 如果是的话,

repsonse.sendRedirect("http://www.google.com");

这将向请求发送代码 302 重定向。

编辑:你到底想要什么?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 2015-05-30
    • 2019-07-03
    • 1970-01-01
    • 2021-03-30
    • 2012-04-18
    • 1970-01-01
    相关资源
    最近更新 更多