Title: RE: [jdjlist] Viewing response headers

--- Greg Nudelman wrote:

>Send your request to the sun snoop servlet:

That works fine for debugging client requests, but I think the problem is the server response.

 

--- Williams, Ryan wrote:

>I'm trying to debug the response headers our application is generating so I

>can know exactly what is getting sent to the browser.  Is there a way in a

>JSP to print out all of the headers?  Like the getHeaderNames() for request,

>only for response instead?

 

Ryan,

One way is to have your JSP/servlet make a raw HTTP request (using Sockets and a PrintWriter) to the server it’s running on and display the response of the server – ie the headers and body – back to the client.  Unfortunately the HttpServletResponse interface does not have methods to extract the response headers that it will use.

 

Alternatively, a few years ago I wrote a basic utility class (HttpClient) that allows you to make HTTP requests and see the full response, including the HTTP headers.  You can send any of the HTTP request methods (GET, POST, HEAD etc), but it defaults to HEAD, since usually that the most useful.  You can see the HTML with view source in a browser so I just want to see the HTTP response head usually, and not the body – ie HTML.  Its basic, but always does the trick for me.  I also use it over the net sometimes to debug a remote site experiencing problems etc, where seeing the full HTTP response is useful.

 

I’ll email you the jar file (includes source) directly as I’m sure the list won’t allow attachments, and I’m sure everyone else wouldn’t appreciate itJ.  (In case anyone else does want a copy, email me directly.)

 

To use it:

Usage: java com.harbourne.utilities.HttpClient [URL][HTTP METHOD][HTTP VER]

Or:   java -jar HttpClient.jar [URL][HTTP METHOD][HTTP VER]

        Eg:     URL: http://www.harbourne.com/

                HTTP METHOD: GET|HEAD|TRACE|OPTIONS

                HTTP VER: 0.9|1.0|1.1

 

Using it for http://www.av.com gives:

-----

java -jar HttpClient.jar http://www.av.com

To:www.av.com:80

Request:HEAD / HTTP/1.1

Connection: close

Referer: http://www.harbourne.com/HttpClient

User-Agent: com.harbourne.utilities.HttpClient

Host: www.av.com

 

Server Response:

HTTP/1.1 302 Found

Server: Resin/1.2.8

Location: http://www.altavista.com/

Content-Type: text/html

Content-Length: 0

Date: Fri, 21 Jun 2002 03:19:49 GMT

----

 

Hope this helps,

Andrew

Professional Java Servlets 2.3

http://www.amazon.com/exec/obidos/ASIN/186100561X

http://www.amazon.co.uk/exec/obidos/ASIN/186100561X

 

-----Original Message-----
From: Williams, Ryan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 20, 2002 3:27 PM
To: JDJList
Subject: [jdjlist] Viewing response headers

 

I'm trying to debug the response headers our application is generating so I
can know exactly what is getting sent to the browser.  Is there a way in a
JSP to print out all of the headers?  Like the getHeaderNames() for request,
only for response instead?

Any ideas would be appreciated.

Thanks!

 

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to