• Post Reply Bookmark Topic Watch Topic
  • New Topic

using HttpURLConnection...

 
Brian Coates
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to use HttpURLConnection to create a connection in a browser?
I've got pageA.jsp and pageB.jsp. pageA successfully creates a HttpURLConnection to pageB and does a few things. However, the browser itself never goes to pageB.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a connection in your first page will in no way affect the browser. That's what a redirect is for.
What are you really trying to accomplish?
 
Brian Coates
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got two webapps that I need to "integrate".
One needs to be able to send a file to the other, and I'm doing that using the HttpURLConnection and sending the file as multipart form data. The webapp on the receiving end requires authentication by a login page.. to do anything.
Using HttpURLConnection, I never get to the login screen... and thus cannot process the data, nor anything else.
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to 'simulate' what a browser would do. Send a user name and password the same way the browser does, probably as part of the request headers, to the login page. And if the response includes a cookie which is expected to be sent to the functional page, like a browser would do since it's on the same domain, your request to the functional page would need to add the cookie(s) to the request.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I've mentioned in serveral other threads, the easiest way to "remote control" another web application is to use a library specifically designed for that purpose. I usually use the free HTTPUnit, but there are others.
Going to all the trouble of implementing the full HTTP model, authentication, cookies etc. is a lot of work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!