Quantcast

Jump to content


Photo

[Java] HTTP Wrapper?


  • Please log in to reply
13 replies to this topic

#1 Eggy

Eggy
  • Banned from trading - Do not trade with this user.

  • 1783 posts


Users Awards

Posted 31 May 2011 - 03:10 PM

I am working on an autobuyer made in Java, which will be open source of course! I was just curious if there are thing's like Glurak's or Nite's or Pete's wrappers for java? There probably is, but right now my google senses are failing me and there is no need to reinvent the wheel if it is something that already exists!

#2 huevoquilmes

huevoquilmes
  • 245 posts

Posted 03 June 2011 - 03:12 PM

I'm doing this also. I already have a Aber up n running in java, no graphic interface though.. I dont understand what you mean as Wrapper (sorry, english isnt my first language)

#3 Eggy

Eggy
  • Banned from trading - Do not trade with this user.

  • 1783 posts


Users Awards

Posted 03 June 2011 - 03:45 PM

If you need some help with the user interface I would be glad to help you out :) Hit me up on msn maybe? [email protected]

#4 Scot

Scot
  • ≡^ᴥ^≡

  • 3935 posts


Users Awards

Posted 03 June 2011 - 05:09 PM

I also need a wrapper for java

#5 huevoquilmes

huevoquilmes
  • 245 posts

Posted 03 June 2011 - 05:11 PM

do you have msn? add me @ [email protected]

#6 jcrdude

jcrdude
  • Oh shit there's a thing here

  • 7001 posts


Users Awards

Posted 03 June 2011 - 05:17 PM

I also need a wrapper for java


I get them for free. I'll make sure to save you one next time.

Spoiler


#7 huevoquilmes

huevoquilmes
  • 245 posts

Posted 03 June 2011 - 05:34 PM

-.- and i opened the spoiler like a dumbass -.-´

#8 Melchoire

Melchoire
  • 5284 posts


Users Awards

Posted 03 June 2011 - 05:39 PM

Why are you guys using java?

I get them for free. I'll make sure to save you one next time.

Spoiler

hhurrhurrhur

PS: doesnt the java api take care of most of the work for an http client?

#9 huevoquilmes

huevoquilmes
  • 245 posts

Posted 03 June 2011 - 05:58 PM

i personally think java is a great programming language... super fast to code up something, and all cross platform.. For http, i use the apache libraries...really easy to use.

http://hc.apache.org...nt-ga/tutorial/

#10 artificial

artificial
  • 186 posts


Users Awards

Posted 06 June 2011 - 05:53 AM

http://www.neocodex....forum/137-java/

#11 vjpwdf

vjpwdf
  • 2 posts

Posted 30 July 2011 - 01:30 PM

Heres some sample code using apaches http-commons (source here http://neopetsutils....c/neopetsutils/)

Add cookies to the http client:
public class NeopetsHttpClient extends HttpClient {    public NeopetsHttpClient(NeopetAccount account) {        getState().addCookies(account.getCookiesFromLogin());    }}

Sample post method:
public class NeopetsPostMethod extends PostMethod {    public NeopetsPostMethod(String uri) {        super(uri);        setNecessaryParameters();    }    public NeopetsPostMethod(String uri, String referrer) {        super(uri);        setNecessaryParameters();        addRequestHeader("Referer", referrer);    }    private void setNecessaryParameters() {        addRequestHeader("Host", "www.neopets.com");        addRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0");        addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");        addRequestHeader("Accept-Encoding", "gzip, deflate");        addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");        addRequestHeader("Content-Type", "application/x-www-form-urlencoded");    }}
Get method:
public class NeopetsGetMethod extends GetMethod {    public NeopetsGetMethod(String uri) {        super(uri);        setNecessaryParameters();    }    public NeopetsGetMethod(String uri, String referrer) {        super(uri);        setNecessaryParameters();        addRequestHeader("Referer", referrer);    }    private void setNecessaryParameters() {        addRequestHeader("Host", "www.neopets.com");        addRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0");        addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");        addRequestHeader("Accept-Encoding", "gzip, deflate");        addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");        addRequestHeader("Content-Type", "application/x-www-form-urlencoded");    }}
Simple login using the above:
public class NeopetsLogin {    public NeopetAccount login(String userName, String password) throws LoginException {        PostMethod postLoginMethod = new NeopetsPostMethod("http://www.neopets.com/login.phtml", "http://www.neopets.com/login/");        postLoginMethod.addParameter("destination", "");        postLoginMethod.addParameter("username", userName);        postLoginMethod.addParameter("password", password);        HttpClient postLoginClient = new HttpClient();        try {            postLoginClient.executeMethod(postLoginMethod);        } catch (IOException e) {            throw new LoginException("Failed to login to neopets!");        }        NeopetAccount account = new NeopetAccount();        account.setCookiesFromLogin(postLoginClient.getState().getCookies());        checkAccountContainsSSOToken(account);        return account;    }    private void checkAccountContainsSSOToken(NeopetAccount account) throws LoginException {        Cookie[] cookies = account.getCookiesFromLogin();        boolean containsSSOToken = false;        for (Cookie cookie : cookies) {            if (cookie.getName().equalsIgnoreCase("ssotoken")) {                containsSSOToken = true;            }        }        if (!containsSSOToken) {            throw new LoginException("Failed to login.  Bad username/password combination.");        }    }}


#12 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 30 July 2011 - 01:56 PM

Heres some sample code using apaches http-commons (source here http://neopetsutils....c/neopetsutils/)

Add cookies to the http client:

public class NeopetsHttpClient extends HttpClient {    public NeopetsHttpClient(NeopetAccount account) {        getState().addCookies(account.getCookiesFromLogin());    }}

Sample post method:
public class NeopetsPostMethod extends PostMethod {    public NeopetsPostMethod(String uri) {        super(uri);        setNecessaryParameters();    }    public NeopetsPostMethod(String uri, String referrer) {        super(uri);        setNecessaryParameters();        addRequestHeader("Referer", referrer);    }    private void setNecessaryParameters() {        addRequestHeader("Host", "www.neopets.com");        addRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0");        addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");        addRequestHeader("Accept-Encoding", "gzip, deflate");        addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");        addRequestHeader("Content-Type", "application/x-www-form-urlencoded");    }}
Get method:
public class NeopetsGetMethod extends GetMethod {    public NeopetsGetMethod(String uri) {        super(uri);        setNecessaryParameters();    }    public NeopetsGetMethod(String uri, String referrer) {        super(uri);        setNecessaryParameters();        addRequestHeader("Referer", referrer);    }    private void setNecessaryParameters() {        addRequestHeader("Host", "www.neopets.com");        addRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0");        addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");        addRequestHeader("Accept-Encoding", "gzip, deflate");        addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");        addRequestHeader("Content-Type", "application/x-www-form-urlencoded");    }}
Simple login using the above:
public class NeopetsLogin {    public NeopetAccount login(String userName, String password) throws LoginException {        PostMethod postLoginMethod = new NeopetsPostMethod("http://www.neopets.com/login.phtml", "http://www.neopets.com/login/");        postLoginMethod.addParameter("destination", "");        postLoginMethod.addParameter("username", userName);        postLoginMethod.addParameter("password", password);        HttpClient postLoginClient = new HttpClient();        try {            postLoginClient.executeMethod(postLoginMethod);        } catch (IOException e) {            throw new LoginException("Failed to login to neopets!");        }        NeopetAccount account = new NeopetAccount();        account.setCookiesFromLogin(postLoginClient.getState().getCookies());        checkAccountContainsSSOToken(account);        return account;    }    private void checkAccountContainsSSOToken(NeopetAccount account) throws LoginException {        Cookie[] cookies = account.getCookiesFromLogin();        boolean containsSSOToken = false;        for (Cookie cookie : cookies) {            if (cookie.getName().equalsIgnoreCase("ssotoken")) {                containsSSOToken = true;            }        }        if (!containsSSOToken) {            throw new LoginException("Failed to login.  Bad username/password combination.");        }    }}


Did you write those neopets utils?

#13 vjpwdf

vjpwdf
  • 2 posts

Posted 30 July 2011 - 04:18 PM

Did you write those neopets utils?


Yes, I wrote them. When I have more time I'll continue to better them and make a java suite.

Vince

#14 Josh

Josh
  • 318 posts

Posted 22 August 2011 - 09:23 PM

http://www.neocodex....ld-source-code/

You can dig one out of there. As far as I know it's as fast as you'll ever need, as well as extremely flexible. Usage of the Page class isn't necessary, it just helps make far prettier code when you're building something as big as a framework :p


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users