This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have written a URL connection program, which would request a webpage from the server. I find that HTTP headers are missing from the the text that I get. Could anyone suggest what can I write more in this program so that I can get to see
HTTP/1.1 200 OK Content-Type: tex/html
apart from the usual <html> tags.
My program ==========
Request for Moderators: Please don't move it in HTML forums, because it is servlet programmers who deal with getting and setting of headers and not HTML programmers.
The URLConnection.getHeaderFields() method lets you access all headers.
Joined: Sep 28, 2001
Hi Ulf , Thanks very much. Would you know how can I obtain everything, the headers, status message and the actual html thing by a single stream. May be I need to use some type of socket connection?
Joined: Mar 22, 2005
If you use Jakarta HttpClient instead of java.net.HttpUrlConnection, there's a class called HttpConnection which gives you access to the raw streams. Maybe that allows you to do that. I've never done it, so I can't help with that.
Added later: Looking at the URLConnection API, it does have getInputStream and getOutputStream methods, which may help you accomplish what you're trying to do. [ August 14, 2005: Message edited by: Ulf Dittmer ]
Joined: Sep 28, 2001
Thanks Ulf, Regarding your second suggestion, that is exactly what I have used in the program, but it does not give the full text ( including headers etc.)
But, I would not like to use some ready made HTTPClient. I would have liked to do the raw Java way.....thanks anyways for your help....
I attempted to reproduce a subset of HttpURLConnection using raw sockets because I wanted control over the socket timeout. It was entertaining, but a pretty big task. To do it you'd have to send all the headers and the request, read and parse all the headers and the response. Starting with the source for the HttpClient version would be a big jump start. Some place down inside it must do exactly that ... read the socket stream and interpret everything that comes through. Maybe you can just insert some hooks and make it call a listener for each header.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
If your interest is to just understand the flow of headers, you can also use external tools like Ethereal,Paros etc which are good sniffers.This will help you to narrow down each and every bit transferred !!!