public static void main(String[] args) throws Exception { HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); WebConversation client = new WebConversation(); doAnonymousLogin(client, "Player 1"); System.out.println(); doJoinGame(client); }
public WebResponse loginForm(String username, String password) throws Exception { WebConversation conversation = new WebConversation(); HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); WebRequest request = new GetMethodWebRequest("http://localhost:8084/LeaveApp/index.jsp"); WebResponse response = conversation.getResponse(request); WebForm loginform = response.getForms()[0]; loginform.setParameter("username", username); loginform.setParameter("password", password); request = loginform.getRequest("submitbutton"); response = conversation.getResponse(request); return response; }
protected void onSetUp() { super.onSetUp(); HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); HttpUnitOptions.setExceptionsThrownOnScriptError(false); HttpUnitOptions.setScriptingEnabled(true); ClientProperties.getDefaultProperties().setAcceptCookies(true); ClientProperties.getDefaultProperties().setAutoRedirect(true); IDatabaseConnection connection = null; try { connection = getConnection(); DatabaseOperation.DELETE_ALL.execute(connection, getDataSet()); DatabaseOperation.CLEAN_INSERT.execute(connection, getDataSet()); } catch (Exception ex) { ex.printStackTrace(); } finally { if (connection != null) { try { connection.getConnection().close(); } catch (SQLException e) { e.printStackTrace(); } } } }
public void login() throws Exception { wc = new WebConversation(); // wc.setProxyServer("127.0.0.1", 8888); HttpUnitOptions.setDefaultCharacterSet("utf-8"); HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); // HttpUnitOptions.setLoggingHttpHeaders(true); HttpUnitOptions.setAcceptCookies(true); wc.setUserAgent( "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11"); ClientProperties.getDefaultProperties().setAcceptCookies(true); WebResponse rs; // rs= wc.getResponse("http://web2.qq.com/"); // setCookie(rs); String url = "http://ptlogin2.qq.com/check?uin=" + this.id + "&appid=1003903&r=0.2842747748363763"; rs = wc.getResponse(url); setCookie(rs); log.info("response:" + rs.getText()); String verifycode = rs.getText().split(",")[1].replaceAll("'", "").replace(");", ""); log.info(this.toString() + " verifycode:" + verifycode); // 需要输入验证码 if (verifycode.length() > 10) { log.error("需要验证码!"); log.info( "验证码地址:" + "http://captcha.qq.com/getimage?aid=1003903&r=0.3318515357095748&uin=" + this.id); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); verifycode = stdin.readLine(); // throw new Exception("需要验证码!"); } String p = PasswordEncrypt.passwordEcrypt(this.password, verifycode); log.info("p:" + p); ; GetMethodWebRequest get = new GetMethodWebRequest("http://ptlogin2.qq.com/login"); get.setParameter("u", this.id); get.setParameter("p", p); get.setParameter("verifycode", verifycode); get.setParameter("webqq_type", "10"); get.setParameter("remember_uin", "1"); get.setParameter("login2qq", "1"); get.setParameter("aid", "1003903"); get.setParameter("u1", "http://web2.qq.com/loginproxy.html?login2qq=1&webqq_type=10"); get.setParameter("h", "1"); get.setParameter("ptredirect", "0"); get.setParameter("ptlang", "2052"); get.setParameter("from_ui", "1"); get.setParameter("pttype", "1"); get.setParameter("dumy", ""); get.setParameter("fp", "loginerroralert"); get.setParameter("action", "2-21-6717"); get.setParameter("mibao_css", "m_webqq"); rs = wc.getResponse(get); setCookie(rs); log.info("response:" + rs.getText()); rs = wc.getResponse("http://web2.qq.com/loginproxy.html?login_level=3"); setCookie(rs); PostMethodWebRequest post = new PostMethodWebRequest("http://d.web2.qq.com/channel/login2"); String ptwebqq = wc.getCookieValue("ptwebqq"); log.info("ptwebqq:" + ptwebqq); String r = "{\"status\":\"online\",\"ptwebqq\":\"" + ptwebqq + "\",\"passwd_sig\":\"\",\"clientid\":\"64768904\",\"psessionid\":null}"; // {"status":"online","ptwebqq":"94355c82e5692825e17a1d95c672b6371e71dec45399845b6d3f14fb23557dfb","passwd_sig":"","clientid":"42599326","psessionid":null} // {"status":"","ptwebqq":"7896466821f021f41ba65eb83d689e671d7b08eb02c0c165ef8589bb772cf9db","passwd_sig":"","clientid":"64768904","psessionid":null} post.setParameter("r", r); wc.setHeaderField("Referer", "http://d.web2.qq.com/proxy.html?v=20110331002&callback=2"); // setCookie(rs); // wc.putCookie("pgv_pvid", "215336480"); // wc.putCookie("pgv_flv", "10.1 r102"); // wc.putCookie("pgv_info", "pgvReferrer=&ssid=s7792437458"); rs = wc.getResponse(post); log.info("login response:" + rs.getText()); JSONObject result = new JSONObject(rs.getText()).getJSONObject("result"); this.psessionid = result.getString("psessionid"); this.vfwebqq = result.getString("vfwebqq"); log.info("psessionid:" + psessionid); }