我试图使用http单元为我的应用程序读取响应标头 -
WebClient webClient = new WebClient();
WebClient.setThrowExceptionOnScriptError(false);
HtmlPage currentPage = webClient.getPage("http://myapp.com");
WebResponse response = currentPage.getWebResponse();
System.out.println(response.getResponseHeaders());
Run Code Online (Sandbox Code Playgroud)
我确实看到了响应头但它们仅限于第一个http get请求.当我使用LiveHTTPHeaders插件for firefox插件时,我得到了所有获取请求和相应的标头响应.
有没有办法为所有后续请求获取http标头,而不仅限于第一次获取?
小智 6
List<NameValuePair> response =currentPage.getWebResponse().getResponseHeaders();
for (NameValuePair header : response) {
System.out.println(header.getName() + " = " + header.getValue());
}
Run Code Online (Sandbox Code Playgroud)
对我来说很好.