This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to retrieve HttpResponse Headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to retrieve HttpResponse Headers" Watch "How to retrieve HttpResponse Headers" New topic
Author

How to retrieve HttpResponse Headers

Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Greetings:
Is their a possibility to retrieve the headers from HttpResponse, i know we can retrieve it from the HttpRequest but i need it from the HttpResponse.
Here's why i need to retrieve the response header:
I have a servlet A running on my local machine that needs to send an object to servlet B that is running on a remote machine as a post message. for servlet B to accept the post message i need to send the cookie(generated by serlvet B) in the post message.
Any help is greatly appreciated.
-Sudhakar
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Can't you just forward the request to servlet B? Am I missing something here?


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
You can only use forward() to something in your own web app.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
no i can't forward the request to servlet B since servlet B is on a remote machine and even if it were i don't want to because i need the response from servlet B to be processed by servlet A.
I am using oreilly's HttpMessage.sendPostMessage(obj) method to perform a post on the remote machine, this returns me an inputstream that contains the response, i am trying to figure out if this response will contain the header info, if so then i can parse the response to retrieve the info needed. Is their a better way to do this??
Any suggestions??
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Whenever I need to send a request to another server and receive and parse the response, I use HTTP Unit
This software offers methods to simply fetch headers from a returned response:

Maybe that might be easier?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yep! I missed the fact that servlet B resides on a remote machine.
[ January 09, 2004: Message edited by: Bosun Bello ]
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Thanks for the response Frank, but i don't have the liberty to use this software, i am bound to use custom made classes or oreilly only.
Any suggestions??
Thanks,
-Sudhakar
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
In which case I suggest you download the source code for HTTPUnit, and use any bits you like in your "custom code". That's the beauty of open source.
Although limiting oneself to just one, limited, open source package, rather than using whatever is most suitable does seem a bit pointless.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve HttpResponse Headers
 
Similar Threads
Servlet - Servlet Communication - Setting the headers
@Responsebody for HTTP msg and a View to show the HTTP response msg
i/o with applets
Setting the HTTP Request Headers
Response header