我正在使用apache httpclient 4.5.3将POST请求提交到另一个不同的网页(例如example.com)。我使用自定义响应处理程序返回响应。响应页面的处理如下:
HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).setDefaultCookieStore(cookieStore).build();
HttpPost httpget = new HttpPost("http://www.example.com/post.php");
...
String responseBody = httpclient.execute(httpget, responseHandler, context);
PrintWriter out = response.getWriter();
out.println(responseBody);
out.close();
问题是在渲染页面时,html页面中的相对URI(如/scripts/test.css)导致HTTP-404,原因很明显,这个脚本在我的tomcat中不存在。
如何处理这个问题?
// SB
答案 0 :(得分:0)
Apache HTTP Client是一个它无法自动处理的HTTP客户端 在HTML页面中引用的资源。需要单独获取这些引用的资源。
Apache HTTP Client简化了处理HTTP协议(及其扩展),如Cookie,缓存,Keep Alive,......
从您的描述中听起来就像您尝试从您自己的tomcat中提供(部分)外部网站。 我们假设没有法律问题。
您有不同的选择: