Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to see how HTTP Works

 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URLConnection.getHeaderFields() method lets you access all headers.
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....

Thanks,
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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....

Sounds like you're looking for this:
http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html

Socket programming is very different from Servlet coding, so this definately won't be the place to go for help if you get stuck.

This would:
http://www.coderanch.com/forums/f-8/sockets
[ August 14, 2005: Message edited by: Ben Souther ]
 
Harish M
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!

Harish
 
Babu Rajendra Prasath Haridass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohan Panigrahi ,

using this code you can get the Header information.


[Edited by Dave. Added code tags and reduced leading whitespace]
[ August 19, 2005: Message edited by: David O'Meara ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic