aspose file tools*
The moose likes Servlets and the fly likes Using commons.HttpClient to post form via servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using commons.HttpClient to post form via servlet" Watch "Using commons.HttpClient to post form via servlet" New topic
Author

Using commons.HttpClient to post form via servlet

Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
I have a web app that posts a form to another site. I need to capture the contents of the form before I post it, so I post to a servlet, capture the data, and use HttpClient to post the form to the remote URL. The problem is when I output the response like this:

OutputStream os = res.getOutputStream();
os.write(post.getResponseBody());
os.flush();

The output is relative to my server and not the actual URL so all the links are broken.

Is there a way with HttpClient to just take the response from the post have it display as it would normally? Or do I need to do some URL rewriting?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Would you care to show us one of the pages that you're trying to do this with? If you look at the HTML on those pages, are the URLs relative or absolute? If they're relative, then you'll definitely have to tack the domain part of the URL...for example, say you call myGetMethod.getResponseBodyAsString() and look at the HTML from www.techies.com/docs/index.html and see a link like this:

<a href='/docs/index.html'>Documentation</a>

You'll need to rewrite it like this:

<a href='www.techies.com/docs/index.html'>Documentation</a>

I know there are legit uses for needing to do this, but know that I'm praying you fail miserably if you're a spammer/phisher or some such villain...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using commons.HttpClient to post form via servlet