I need to check ETag from the header response of requesting URL. I know that when request URL, then response will be html, css, js and images.

My issue: How to read header for all these resources including the html when requesting URL?

For HttpClient if you enter URL then it will give header and response only for html!! it didn't return the header for all loading resources which are involved with this URL and will be loaded associated with this URL.

if I request only css, then it will give me a right header response for this style.

HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://www.mkyong.com/wp-content/themes/mkyong/css/prism.css");

HttpResponse response = client.execute(request);
for (Header header : response.getHeaders("ETag")) 
    System.out.println(header.getName()+" == "+header.getValue());

But if I tried to but the main URL: http://www.mkyong.com, then it will give me only response for the main html.

How to fetch them?


When your web browser requests a URL, the response is just the page and anything embedded in the page. Your web browser parses the response, determines what other resources are referenced by the page, and sends additional requests to fetch those resources, one resource per request.

You will have to do the same thing.

  • How to determines what other resources are referenced by the page?
    – Hana90
    Jun 19 '16 at 7:02
  • No general way other than parsing the response and looking for URLs. And of course if there is Javascript in the page, that might load other resources too. A way to finesse the problem is to ask whether you really need to load the other resources. Presumably the browser caches them after the first page visit.
    – user246
    Jun 19 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.