Skip to main content

Reading Header

No replies
nature_antimatter
Offline
Joined: 2009-06-19
Points: 0

Hi,

I am trying to read headers. I am using HttpClient API to read them but it not getting me all the headers. Below is the code I am using to retrieve them
==========================================
int returnCode = 0;
HttpClient client = new HttpClient();
HeadMethod method = new HeadMethod("http://in.yahoo.com/");
try{
returnCode = client.executeMethod(method);
System.out.println("returnCode...."returnCode);
Header[] headers = method.getResponseHeaders();
for (int j = 0; j < headers.length; j+) {
System.out.println(headers[j]);
}
if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.out.println("This method is not implemented by this URI");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
method.releaseConnection();
}
=======================================
In return of the above code I get

Date: Sat, 20 Jun 2009 05:39:57 GMT
Set-Cookie: D=_ylh=X3oDMTFnODlzcWxiBF9TAzk2ODU2MTU5BHBpZAMxMjQ1NDc0NzIwBHRlc3QDMAR0bXBsA2luZGV4LnBocA--; path=/; domain=.yahoo.com
Cache-Control: private
Connection: close
Content-Type: text/html; charset=utf-8

=========================================
where as in the browser (using firebug) I can see

Date: Sat, 20 Jun 2009 05:37:38 GMT
Set-Cookie: D=_ylh=X3oDMTFnODlzcWxiBF9TAzk2ODU2MTU5BHBpZAMxMjQ1NDc0NzIwBHRlc3QDMAR0bXBsA2luZGV4LnBocA--; path=/; domain=.yahoo.com
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip

=======================================
I am looking for the ways to read all the headers so my question is how it is possible? and why I am not able to see all the headers?