This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Sockets and Internet Protocols and the fly likes Login to a web forum Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Login to a web forum" Watch "Login to a web forum" New topic
Author

Login to a web forum

John Doven
Greenhorn

Joined: Jul 18, 2010
Posts: 2
I am trying to create a java program that will log in to a PHP web forum, then navigate to a page that can only be accessed by a logged in user and finally printout the HTML source code for that page. I have been trying to figure out a solution to this problem to no avail. I would consider myself a novice programmer (I took some classes several years ago).

I think the problem that I'm running into has to do with handling cookies. After failing to figure this out from scratch, I came across the HTTPClient package and I have been trying to run their log in example found at HTTP Client Example however that doesn't seem to work. Can anyone point me in the right direction or give me an idea of where I am going wrong. Any insight is very appreciated as I'm very frustrated right now. Thanks.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

TellTheDetails. Show us what you are trying and what is not working. We are happy to help if we know what is the problem


apigee, a better way to API!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35220
    
    7
I'd advise to use a library like HtmlUnit instead of HTTPClient; it has a much higher level API for working with web sites.


Android appsImageJ pluginsJava web charts
John Doven
Greenhorn

Joined: Jul 18, 2010
Posts: 2
Okay I decided to use HTMLUnit as suggested. I'm still not getting it to print out the "hidden" URL so far. I created an example user name and password on a random forum for testing. Any advice? Thanks.

Kamal Wickramanayake
Greenhorn

Joined: Jul 10, 2010
Posts: 27
I haven't used HTMLUnit. But instead of


//Webpage only accessible to logged in users URL+private.php
printWebpage("http://www.honda-tech.com/private.php");


what if you try something like

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35220
    
    7
The printWebpage method does not use HtmlUnit, so it has no idea of what happened before. You need to work with page2 to obtain the results of your logging in.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Login to a web forum
 
Similar Threads
Detecting Crashes in JBoss 4.0.2
j_security_check login
Log4j in JBOSS
Jdbc, j_security, and other issues
URL Parameters AND Encode in JSP