회사에서 login을 주기적으로 확인하여

 

 

HTTPClient 3.0으로 로그인을 테스트를 할 수 있다.

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

문제는 https 다.

난 이렇게 해결했다.

 

HTTPClient 3.0 버젼

 

        HttpClient client = new HttpClient();

         client.getState().setCredentials(
            new AuthScope("ids.google.com", 443 ),
            new UsernamePasswordCredentials("", "" )
        );

         client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

            PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

 

 

 

HTTPClient 2.0 버젼

 

 

         HttpClient client = new HttpClient();

         client.getState().setCredentials(
                "realm", "ids.google.com",
                new UsernamePasswordCredentials("", "" )
            );

       client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");

 

       PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }


 

Posted by 김용환 '김용환'

댓글을 달아 주세요