我正在尝试重定向到"某些网址"使用Apache Httpclient 4.3。 当下面的代码工作时,我得到" 200 OK"状态,但在浏览器中没有任何变化。 这段代码在servlet的doGet()方法中,我不想使用response.sendRedirect()。
如何在浏览器中查看已重新设定的网页网址?
String url = "some url";
HttpClient instance =
HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
try {
HttpResponse response = instance.execute(new HttpGet(url));
} catch (IOException e) {
e.printStackTrace();
}
答案 0 :(得分:3)
根据您问题中的描述,这是您的筹码:
浏览器向基于Servlet的服务器发送HTTP请求。基于Servlet的服务器使用Apache HttpClient
向"某些URL"发送HTTP请求。 "some url"
使用重定向302进行响应,由HttpClient
LaxRedirectStrategy
"some url"
跟随HttpClient
。 {{1}}响应其他一些HTTP响应。基于Servlet的服务器以200 OK完成并响应浏览器客户端。
浏览器客户端与您在servlet中使用的Apache {{1}}实例之间存在绝对无关系。
如何在浏览器中查看返回的网页的网址?
这没有意义。如果您想在浏览器中看到网址,则需要通过浏览器向该网址发送请求,或者让浏览器跟随重定向。