• Post Reply Bookmark Topic Watch Topic
  • New Topic

Performing a POST (or GET) on the server  RSS feed

 
James Davison
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to perform a POST or GET request to another server while in the process of handling the current request?

My scenario is this: I need to POST to second servlet which may or may not be on a different server depending upon the production/test/development environment. The second servlet was originally designed to handle Ajax requests. I could possibly do a Ajax call after I displayed my page but it will make my life much more complicated. I simply want to do a POST (within a POST), consume the response, and continue handling the current POST request.

Is what I want to do possible? If so, would someone please provide a hint as to how?

Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could explore the classes in the java.net package and roll your own, but I'd recommend checking out the HttpClient project.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
talking to another server is easy, that's how one talks to a database server.

I've rolled my own HTTP client code in Java, and I agree with Bear, use a library. HTTP 1.0 was fairly easy, but you need to support things like clunked (or chunked, I forget) responses. And you really want to be able to use HTTPS
which is much too much like work to do by hand.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!