Java Login to SSL Website

Please help me download a page from behind a secure site with username and password authentication and post method.  Specifically, I would like to download from nfl.com under fantasy football.  I am using Apache HttpClient, so it would be real nice if answers used that.  My problem has something to do with cookies.  The error message is that the cookie has been rejected.  Even though I am using Java, and my email address appears no where in the Java code, the rejected cookies contain my email address.   So I am wondering whether the Java code is accessing my IE cookies.  I have tried all of the cookie policies.


public static void main(String[] args) throws HttpException, IOException {
String fanUrlStr = "https://id2.s.nfl.com/fans/login?returnTo=%2Ffantasy%2Fleaguemanager";
HttpClient c = new HttpClient();
c.getParams().setParameter("http.protocol.single-cookie-header", true);
c.getState().clearCredentials();
c.getState().clear();
c.getState().clearCookies();
PostMethod p = new PostMethod(fanUrlStr);
p.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
p.addParameter("username", "a_user");
p.addParameter("password", "some_passwod");
c.executeMethod(p);
String response = p.getResponseBodyAsString();
p.releaseConnection();
FileWriter fw = new FileWriter(new File("C:/out.html"));
fw.write(response);
fw.close();
}

Open in new window

ff10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VenabiliCommented:
I do not see you even attempting to login there... so if this is a login based site, you need to login using the HttpClient before you do anything else.

Something like this http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/BasicAuthenticationExample.java?view=markup should be enough in most cases.

Unless if they use form login, in which case you need something like this:
http://www.java-tips.org/other-api-tips/httpclient/how-to-perform-form-based-logon.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ff10Author Commented:
solution was not complete
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.