Results 1 to 1 of 1
- 05-15-2010, 03:21 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
login with cookies using Apache httpClient
Hello everybody,
I just was thinking about how to realize an automatic login with cookie authentification. I found some bibs from Apache: httpClient
I used this tutotial to figure that out:
Java Tips - How to use HTTP cookies
Authentication works fine, so I get a valid cookie back to my HttpClient instance. But unfortunately if I want to get the actual content page I always get the error of an expired session.
The login works with an SSL secured page. Rest is not secured.
This is my example code:
Can anybody help me?Java Code:// Get HTTP client instance HttpClient httpclient = new HttpClient(); httpclient.getHttpConnectionManager(). getParams().setConnectionTimeout(30000); httpclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); // POST URL String postURL = "https://secure.thisisjustapage.com/start.php"; PostMethod httppost = new PostMethod(postURL); httppost.addParameter("loginName", "mylogin"); httppost.addParameter("pass", "mypass"); try{ httpclient.executeMethod(httppost); System.out.println(httppost.getStatusLine()); } catch(Exception e) { e.printStackTrace(); } httppost.releaseConnection(); // Now, I have my valid cookies // GET URL String strURL = "http://www.thisisjustapage.com/start.php"; // Get HTTP GET method GetMethod httpget = new GetMethod(strURL); int result = 0; try{ // Execute HTTP GET result = httpclient.executeMethod(httpget); } catch(Exception e) { e.printStackTrace(); } // Display status code System.out.println("Response status code: " + result); System.out.println(httpget.getResponseBodyAsString()); // Release current connection to the connection pool // once you are done httpget.releaseConnection(); }
Thanks
Mac
Similar Threads
-
Using HttpClient
By jdetloff in forum New To JavaReplies: 4Last Post: 01-06-2010, 10:43 AM -
Using HttpClient with Eclipse
By jdetloff in forum EclipseReplies: 4Last Post: 01-06-2010, 09:47 AM -
Apache Axis2 is built on Apache AXIOM, a new high performance, pull-based XML object.
By anusoniaa in forum XMLReplies: 0Last Post: 11-15-2008, 07:29 AM -
How to write the login application using cookies
By lukky in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-19-2008, 06:06 PM -
cannot open database requested in login. Login fails
By banduskank in forum JDBCReplies: 0Last Post: 06-25-2008, 12:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks