Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to simulate login to a web site?

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I have a certain Web site that requires Username and Password in order to enter, which I have.
I would like to create a program that fetches such info from that site and in order to do that I first need to connect the site and simulate login through code. Can anyone please show me a code example of how to do such thing?

Thanx,
Roy
 
Can I correct your terminology a bit. You're not 'simulating' login ... you're actually logging in programmatically rather than manually.

Saying 'simulating login' has overtones of 'login spoofing' which is a no-no.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
I take it you have the correct login details ?

--------------------------------------------------
Free Database Connection Pooling Software
 
Well, I've never tried it but I suppose you'd need to work out the http request required by looking at the login page and how it submits the login info (i.e. POST / GET).

Once you've got the http request built, with your login info in it, you'd use a HttpURLConnection (or maybe an HttpsURLConnection if the site is using SSL for login submissions) to send it.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
... and you have the correct login details, obviously [smile].

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Can you or someone elase please show me a piece of code example assuming it uses http with POST method?
 
I've answered this question many many times - search the forum for "httpurlconnection", or look at this thread, one of my answers - it shows how to download an image from a website. You will need to modify it to submit data to a website etc.

thread269-829678

--------------------------------------------------
Free Database Connection Pooling Software
 
Hey sedj,

I tried your code from thread269-829678 and I get Connection time out. Now, I've noticed that I get this on every URL I am trying so I beleive our Network here may be blocking this. If I use a proxy in my Network is there any way to use Java code in order to open the connection to the URL through this proxy server?
 
By the way, it passes the testURL.openConnection() which means it found the URL. It fails on the connect() method of HttpURLConnection Class. And by the way, I tried the method usingProxy() of HttpURLConnection and it didn't help. Any ideas why?
 
Solved it with:

System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "prx" );
System.getProperties().put( "proxyPort", "8080" );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top