Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading all response headers using HtmlUnit

Tags:

java

htmlunit

I was trying to use http unit to read response header for my application -

WebClient webClient = new WebClient();
WebClient.setThrowExceptionOnScriptError(false);
HtmlPage currentPage = webClient.getPage("http://myapp.com");
WebResponse response = currentPage.getWebResponse();
System.out.println(response.getResponseHeaders());  

I do get to see the response headers but they are limited to only first http get request. When I used LiveHTTPHeaders plugin for firefox plugin I got to all the get requests and corresponding header responses.

Is there any way to get http header for all subsequent requests and not being limited to just first get?

like image 947
Tarun Avatar asked Feb 03 '12 12:02

Tarun


1 Answers

List<NameValuePair> response =currentPage.getWebResponse().getResponseHeaders();
for (NameValuePair header : response) {
     System.out.println(header.getName() + " = " + header.getValue());
 }

works fine for me.

like image 112
Birhanu Eshete Avatar answered Sep 19 '22 14:09

Birhanu Eshete