This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using commons.HttpClient to post form via servlet

 
Michael J. Makunas
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic