A basic Gaia Login written in Java that also dumps all of the cookies, pre and post login.
Edit the xxxx and input your own username and password there.Code:/* * Written by Flareboy323 of LogicalGamers.com * Requires Apache HTTPComponents core and client * libraries to compile. */ import java.util.ArrayList; import java.util.List; import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; /** * A example that demonstrates how HttpClient APIs can be used to perform * form-based logon. */ public class ClientFormLogin { public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try { HttpGet httpget = new HttpGet("http://www.gaiaonline.com/auth/login"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } HttpPost httpost = new HttpPost("http://www.gaiaonline.com/auth/login"); List <NameValuePair> nvps = new ArrayList <NameValuePair>(); nvps.add(new BasicNameValuePair("username", "xxxx")); nvps.add(new BasicNameValuePair("password", "xxxx")); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); response = httpclient.execute(httpost); entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } } }
Results 1 to 11 of 11
Thread: Basic Java Gaia Login
- 25 Nov. 2012 08:25pm #1
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00
Basic Java Gaia Login
Last edited by 323; 25 Nov. 2012 at 08:31pm.
- 25 Nov. 2012 09:50pm #2
Doesn't even look like it'd work.
Nice job on the effort though.
- 25 Nov. 2012 09:56pm #3
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00
Why do you say that it doesn't look like it would work? I'm adding a comment poster onto it right now, to be completely positive that it logs you in. Know of any better way to make sure that it logs you in?
EDIT: You're right, it doesn't work. I'm getting a 401 Unauthorized when I try to post the comments. Any idea why it's not working? I'm looking at Artificial's and the other one and don't see anything extraLast edited by 323; 25 Nov. 2012 at 10:15pm.
- 25 Nov. 2012 10:41pm #4
Probably invalid post data in the page form fields.
- 25 Nov. 2012 11:07pm #5
You're only posting a username and password. Maybe you should consider using an http class rather than doing it all manually.
- 25 Nov. 2012 11:11pm #6
Basically this.
Try reading this post. http://forum.logicalgamers.com/progr...tml#post366770
- 25 Nov. 2012 11:41pm #7
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00
- 25 Nov. 2012 11:48pm #8
Use a wrapper like the one in my post rather than doing extra manual labor like initializing the http instance, cookie management, generally more coding, etc. The main things that should be exposed to you is what is relevant to you: namely GET/POST requests from the client.
- 26 Nov. 2012 12:18am #9
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00
I would love for that, but I couldn't find any HTTP wrappers for Java. The only thing close to it that was easy to use that I found was this one, the Apache HTTP Components thing. I might try out the one you linked me to on Github, it looks promising, but is it fully developed?
- 26 Nov. 2012 12:25am #10
It should at the very least be capable of simple tasks like GET/POST requests (and of course handles the cookies for you), which is normally all you need. Me or him could always expand on it, or even you could as it is open source, so you can always tailor it to your needs.
If you have any problems w/ it just post away.
Edit: And yeah, we've used it for quite a few projects so it should be pretty stable.Last edited by The Unintelligible; 26 Nov. 2012 at 12:27am.
- 26 Nov. 2012 02:09pm #11
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.00