File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Simulating browser in a application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Simulating browser in a application" Watch "Simulating browser in a application" New topic
Author

Simulating browser in a application

san jan
Greenhorn

Joined: Sep 26, 2000
Posts: 24
Hi,
may i know how to simulate a browser in an application.
i wanna send details of a form to a url on internet & wanna catch the response & give status whether the submit was perfect or not.
i wanna find whether this can be done by URLConnection? can we submit a form through URLConnection?
its simulating a browser functionality in the application.
-santu
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Here is the almost complete code for POSTING data to a HTTP resource, you can fill in the exception handling to suit.

James.
san jan
Greenhorn

Joined: Sep 26, 2000
Posts: 24
hi james,
thanks a lot, but am behind a firewall/proxy. i am getting following exception. how to set for a proxy address,port, and also provide username and password, so that application makes the connection.
the following exception i am getting at "httpConnection.connect()" line.
I have tried it but in vain.
can i have ur e-mail id?
-santu

[This message has been edited by santosh kumar janmanchi (edited August 04, 2001).]
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
If you are behind a firewall, you need to define some system properties that point to your proxy:
System.setProperty("http.proxyHost", "myproxy.myserver.com");
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxySet", "true");
Note that this works for URLConnection access, but not plain sockets.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
san jan
Greenhorn

Joined: Sep 26, 2000
Posts: 24
Hi Phil,
thank u. now i am able to connect to internet sites. i am able to read sites info.
<B>BUT AM NOT ABLE TO POST DATA TO ANY SITE</B>
am giving proxy settings, am giving authentication info thru subclassing Authenticator & then using its static method setDefault().
site i tested is : http://www.123greetings.com/
from this site's source i took the form that searches the site for greeting cards particular to some given words(can see under "Cool Services").
The code snippet i used for posting is

<B>I have tried all the above 3 options to post to the site, the response i get is '200', that is ok.
But the response page should contain 'searched word:birthday' as i have given birthday as the word to search, but instead gives in response page as 'searched word:' i.e., null is taken.</B>
not only with this, but with many other sites also am not getting the page am supposed to get, infact the post is not happening in a proper manner.
MAY I KNOW WHAT COULD BE THE REASON?
-santu
san jan
Greenhorn

Joined: Sep 26, 2000
Posts: 24
hi,
infact the code works perfectly fine with the following site http://java.sun.com/cgi-bin/backwards
which is given in sun's tutorials for testing of posting data to a url using url-connection objects.
but the same program is not posting data to any other sites, its not working perfectly.
-santu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simulating browser in a application