• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simulating browser in a application

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
san jan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic