• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java client querying web page

 
Bill Denniston
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a greenhorn. I'm an experienced (actually, just old) programmer, but new to Java. I've read Head First Java and am trying to muddle through some simple but real initial applications.

I'm looking for examples of simple java client apps that query (i.e. submit POST requests with form parameters to) web pages. I can find lots about writing servlets to respond to such requests, but haven't found anything that shows how to emulate a browser sending the request. (I have found examples of that perform GET operations by simply opening a URL stream.) Any suggestions on how to explore this functionality would be appreaciated. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the java.net.URL.openConnection() method.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find the HttpClient toolkit useful for emulating the browser side of web application interaction. For example, it can handle cookies like a browser does.
Bill
 
Frank Carver
Sheriff
Posts: 6920
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I second Franks suggestion of HttpUnit. Don't let the fact that it has its roots in unit testing turn you off - it is a very handy tool for accessing web pages, and it can even deal with simple JavaScript. It has its own API that lets you access the contents of the web page, but also presents that web page as a DOM object, so there are a number of possibilities for further processing.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this has more to do with writing client code in Java than servlets, I'm going to move it to the "Sockets And Internet Protocols" forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic