• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Need to see how HTTP Works

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
https://coderanch.com/forums/f-8/sockets
[ August 14, 2005: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Everybody! Do the Funky Monkey! Like this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic