Java Code Examples for org.apache.http.cookie.Cookie#getValue()

The following examples show how to use org.apache.http.cookie.Cookie#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: A6UserInfoSPUtil.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
public void saveCookies(List<Cookie> cookies){
	String strCookie = "";
       Date sessionTime = null;
       
       if (cookies != null && !cookies.isEmpty()) {
           for (int i = 0; i < cookies.size(); i++) {
           	Cookie cookie = cookies.get(i);
           	if (cookie.getName().equalsIgnoreCase("JSESSIONID")){
            	strCookie += cookie.getName() + "="
	                     + cookie.getValue() + ";domain="
	                     +cookie.getDomain();
	            sessionTime = cookies.get(i).getExpiryDate();
           	}
           }
       }
       editor.putString("cookies", strCookie);
	editor.commit();
	editor.putString("cookiesExpiryDate", (sessionTime == null)?null:TimeUtil.getDTFormat().format(sessionTime));
	editor.commit();
}
 
Example 2
Source File: DownloadFile.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private String getCookie() {
    String cookieStr = "";
    for (Cookie cookie : AbstractApp.bitherjSetting.getCookieStore().getCookies()) {
        cookieStr = cookie.getName() + "=" + cookie.getValue() + ";";
    }
    //LogUtil.d("cookie",cookieStr);
    if (!Utils.isEmpty(cookieStr)) {
        cookieStr = cookieStr.substring(0, cookieStr.length() - 1);
    }
    //LogUtil.d("cookie","substring:"+cookieStr);
    return cookieStr;
}
 
Example 3
Source File: FusionPipelineClient.java    From storm-solr with Apache License 2.0 5 votes vote down vote up
protected synchronized void clearCookieForHost(String sessionHost) throws Exception {
  Cookie sessionCookie = null;
  for (Cookie cookie : cookieStore.getCookies()) {
    String cookieDomain = cookie.getDomain();
    if (cookieDomain != null) {
      if (sessionHost.equals(cookieDomain) ||
        sessionHost.indexOf(cookieDomain) != -1 ||
        cookieDomain.indexOf(sessionHost) != -1)
      {
        sessionCookie = cookie;
        break;
      }
    }
  }

  if (sessionCookie != null) {
    BasicClientCookie httpCookie =
      new BasicClientCookie(sessionCookie.getName(),sessionCookie.getValue());
    httpCookie.setExpiryDate(new Date(0));
    httpCookie.setVersion(1);
    httpCookie.setPath(sessionCookie.getPath());
    httpCookie.setDomain(sessionCookie.getDomain());
    cookieStore.addCookie(httpCookie);
  }

  cookieStore.clearExpired(new Date()); // this should clear the cookie
}
 
Example 4
Source File: CookieUtils.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return the name=value of the cookie.
 * @param httpContext HttpContext in which the cookies store
 * @param name the name of the cookie.
 * @return the name and the value of the cookie.
 */
public static String getCookieNameValue(HttpContext httpContext, String name){
    CookieStore cookieStore = (CookieStore) httpContext.getAttribute(ClientContext.COOKIE_STORE);
    List<Cookie> cookies = cookieStore.getCookies();
    Cookie cookie;
    String cookieName;
    for(int i = 0; i < cookies.size(); i++){
        cookie = cookies.get(i);
        cookieName = cookie.getName();
        if(cookieName.contains(name)){
            return cookieName + "=" + cookie.getValue();
        }
    }
    return null;
}
 
Example 5
Source File: FormLoginAuthenticationCsrfTokenInterceptor.java    From mojito with Apache License 2.0 5 votes vote down vote up
/**
 * @return null if no sesson id cookie is found
 */
protected String getAuthenticationSessionIdFromCookieStore() {
    List<Cookie> cookies = cookieStore.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(COOKIE_SESSION_NAME)) {
            String cookieValue = cookie.getValue();
            logger.debug("Found session cookie: {}", cookieValue);
            return cookieValue;
        }
    }

    return null;
}
 
Example 6
Source File: ZShareUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void loginZshare() throws Exception {
    HttpParams params = new BasicHttpParams();
    params.setParameter(
            "http.useragent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    DefaultHttpClient httpclient = new DefaultHttpClient(params);

    System.out.println("Trying to log in to zshare.ma");
    HttpPost httppost = new HttpPost(zsharedomain);
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("op", "login"));
    formparams.add(new BasicNameValuePair("login", uname));
    formparams.add(new BasicNameValuePair("password", pwd));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    httppost.setEntity(entity);
    HttpResponse httpresponse = httpclient.execute(httppost);
    System.out.println("Getting cookies........");
    Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
    Cookie escookie = null;

    while (it.hasNext()) {
        escookie = it.next();
        System.out.println(escookie.getName() + "=" + escookie.getValue());
        if (escookie.getName().equalsIgnoreCase("xfss")) {
            xfsscookie = "xfss=" + escookie.getValue();
            System.out.println(xfsscookie);
            login = true;
            System.out.println("Zshare Login success :)");
        }

    }
    if (!login) {
        System.out.println("Zshare login failed :(");
    }

}
 
Example 7
Source File: RegisterMobileFragment.java    From letv with Apache License 2.0 5 votes vote down vote up
private String getCaptchaId(HttpClient httpClient) {
    List<Cookie> cookies = ((AbstractHttpClient) httpClient).getCookieStore().getCookies();
    String captchaId = null;
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = (Cookie) cookies.get(i);
        String cookieName = cookie.getName();
        if (!TextUtils.isEmpty(cookieName) && cookieName.equals("captchaId")) {
            captchaId = cookie.getValue();
        }
    }
    return captchaId;
}
 
Example 8
Source File: UploadedDotToUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void loginUploadedDotTo() throws Exception {
    HttpParams params = new BasicHttpParams();
    params.setParameter(
            "http.useragent",
            "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    DefaultHttpClient httpclient = new DefaultHttpClient(params);

    System.out.println("Trying to log in to uploaded.to");
    HttpPost httppost = new HttpPost("http://uploaded.to/io/login");
    httppost.setHeader("Cookie", phpsessioncookie);
    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    formparams.add(new BasicNameValuePair("id", ""));
    formparams.add(new BasicNameValuePair("pw", ""));
    formparams.add(new BasicNameValuePair("_", ""));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    httppost.setEntity(entity);
    HttpResponse httpresponse = httpclient.execute(httppost);
    System.out.println("Getting cookies........");
    Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
    Cookie escookie = null;
    while (it.hasNext()) {
        escookie = it.next();
        if (escookie.getName().equalsIgnoreCase("login")) {
            logincookie = "login=" + escookie.getValue();
            System.out.println(logincookie);
            login = true;
        }
        if (escookie.getName().equalsIgnoreCase("auth")) {
            authcookie = "auth=" + escookie.getValue();
            System.out.println(authcookie);
        }

    }

    tmp = getData("http://uploaded.to/");
    userid = parseResponse(tmp, "id=\"user_id\" value=\"", "\"");
    userpwd = parseResponse(tmp, "id=\"user_pw\" value=\"", "\"");
}
 
Example 9
Source File: HtmlUnitBrowserCompatCookieSpec.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
@Override
public List<Header> formatCookies(final List<Cookie> cookies) {
    Collections.sort(cookies, COOKIE_COMPARATOR);

    final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        final Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        final String cookieName = cookie.getName();
        final String cookieValue = cookie.getValue();
        if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) {
            HtmlUnitBrowserCompatCookieHeaderValueFormatter.INSTANCE.formatHeaderElement(
                    buffer,
                    new BasicHeaderElement(cookieName, cookieValue),
                    false);
        }
        else {
            // Netscape style cookies do not support quoted values
            buffer.append(cookieName);
            buffer.append("=");
            if (cookieValue != null) {
                buffer.append(cookieValue);
            }
        }
    }
    final List<Header> headers = new ArrayList<>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
 
Example 10
Source File: SendSpaceUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static void loginSendSpace() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to sendspace");
        HttpPost httppost = new HttpPost("http://www.sendspace.com/login.html");
        httppost.setHeader("Cookie", sidcookie + ";" + ssuicookie);
//        httppost.setHeader("Referer", "http://www.filesonic.in/");
//        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("action", "login"));
        formparams.add(new BasicNameValuePair("submit", "login"));
        formparams.add(new BasicNameValuePair("target", "%252F"));
        formparams.add(new BasicNameValuePair("action_type", "login"));
        formparams.add(new BasicNameValuePair("remember", "1"));
        formparams.add(new BasicNameValuePair("username", ""));
        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);

        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("ssal")) {
                ssalcookie = escookie.getName() + "=" + escookie.getValue();
                System.out.println(ssalcookie);
                login = true;
            }

        }

    }
 
Example 11
Source File: CSDN.java    From FreeServer with Apache License 2.0 5 votes vote down vote up
/**
     * @Author Demo_Liu
     * @Date 2019/6/12 14:45
     * @description 获取csdn cookie
     * @Param [userInfo]
     * @Reutrn java.lang.String
    */
    public static String getCSDNCookie(UserInfo userInfo) throws IOException, URISyntaxException {
        CookieStore cookieStore = new BasicCookieStore();
        CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
//        //登录接口1
//        JSONObject jsonObject = JSONObject.fromObject(HttpUtil.getGetRes(httpClient, UrlUtil.CSDN_LOGIN1 , ParamUtil.getCSDNLogin1(userInfo.getBlogUser())));
//        log.info("CSDN-login1返回:"+jsonObject.toString());
//        //登录接口2
//        if("success".equals(jsonObject.getString("message"))) {
            JSONObject json = JSONObject.fromObject(HttpUtil.getPostRes(httpClient, UrlUtil.CSDN_LOGIN2, new StringEntity(ParamUtil.getCSDNLogin2(userInfo).toString())));
            log.info("CSDN-login2返回:"+json.toString());
            String cookieStr = "";
            if ("success".equals(json.getString("message"))) {
                for (Cookie cookie : cookieStore.getCookies()) {
                    System.out.println(cookie.getName()+"="+cookie.getValue());
                    //这里为什么是这些cookie?  实践出真知!!!---demo_liu
                    String name = cookie.getName();
                    if(name.equals("uuid_tt_dd") || name.equals("dc_session_id") || name.equals("SESSION") ||
                       name.equals("UserName")   || name.equals("UserInfo")      || name.equals("UserToken")){
                        cookieStr += cookie.getName() + "=" + cookie.getValue() + ";";
                    }
                }
                cookieStr+="firstDie=1;";
                log.info("CSDN cookie:"+cookieStr);
                return cookieStr;
            } else {
                //未能成功请求
                return "99";
            }
//        }else{
//            return "99";
//        }
    }
 
Example 12
Source File: MyHttpClient.java    From xiaoV with GNU General Public License v3.0 5 votes vote down vote up
public static String getCookie(String name) {
	List<Cookie> cookies = cookieStore.getCookies();
	for (Cookie cookie : cookies) {
		if (cookie.getName().equalsIgnoreCase(name)) {
			return cookie.getValue();
		}
	}
	return null;

}
 
Example 13
Source File: HTTPSession.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Extract the sessionid cookie value
 *
 * @return sessionid string
 */
public String getSessionID() {
  String sid = null;
  String jsid = null;
  List<Cookie> cookies = this.sessioncontext.getCookieStore().getCookies();
  for (Cookie cookie : cookies) {
    if (cookie.getName().equalsIgnoreCase("sessionid"))
      sid = cookie.getValue();
    if (cookie.getName().equalsIgnoreCase("jsessionid"))
      jsid = cookie.getValue();
  }
  return (sid == null ? jsid : sid);
}
 
Example 14
Source File: LetitbitUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void loginLetitbit() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to letitbit.com");
        HttpPost httppost = new HttpPost("http://letitbit.net/");
        httppost.setHeader("Cookie", phpsessioncookie);
//        httppost.setHeader("Referer", "http://www.filesonic.in/");
//        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("act", "login"));
        formparams.add(new BasicNameValuePair("login", ""));
        formparams.add(new BasicNameValuePair("password", ""));


//        formparams.add(new BasicNameValuePair("remember", "1"));
//        formparams.add(new BasicNameValuePair("username", ""));
//        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);

        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("log")) {
                logcookie = "log=" + escookie.getValue();
                System.out.println(logcookie);
            }
            if (escookie.getName().equalsIgnoreCase("pas")) {
                pascookie = "pas=" + escookie.getValue();

                System.out.println(pascookie);
            }
            if (escookie.getName().equalsIgnoreCase("host")) {
                hostcookie = "host=" + escookie.getValue();
                System.out.println(hostcookie);
            }
           


        }


    }
 
Example 15
Source File: GrUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void loginGrUpload() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to grupload.com");
        HttpPost httppost = new HttpPost("http://grupload.com/");

//        httppost.setHeader("Referer", "http://www.filesonic.in/");
//        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();

        formparams.add(new BasicNameValuePair("op", "login"));
        formparams.add(new BasicNameValuePair("redirect", "http://grupload.com"));
        formparams.add(new BasicNameValuePair("login", "007007dinesh"));
        formparams.add(new BasicNameValuePair("password", "************************"));



//        formparams.add(new BasicNameValuePair("remember", "1"));
//        formparams.add(new BasicNameValuePair("username", ""));
//        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);

        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("login")) {
                logincookie = "login=" + escookie.getValue();
                System.out.println(logincookie);
            }
            if (escookie.getName().equalsIgnoreCase("xfss")) {
                xfsscookie = "xfss=" + escookie.getValue();
                System.out.println(xfsscookie);
                login = true;
            }
        }

        if (login) {
            System.out.println("Grupload Login successful :)");
        } else {
            System.out.println("Grupload Login failed :(");
        }


    }
 
Example 16
Source File: ZidduUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void loginZiddu() throws Exception {



        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to ziddu");
        HttpPost httppost = new HttpPost("http://www.ziddu.com/login.php");
        httppost.setHeader("Referer", "http://www.ziddu.com/");
        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
//        httppost.setHeader("Cookie", cfduidcookie);
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("email", "[email protected]"));
        formparams.add(new BasicNameValuePair("password", ""));

        formparams.add(new BasicNameValuePair("action", "LOGIN"));

        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);

        System.out.println("Getting cookies........");
        System.out.println(httpresponse.getStatusLine());
        Header[] allHeaders = httpresponse.getAllHeaders();
        for (int i = 0; i < allHeaders.length; i++) {
            System.out.println(allHeaders[i].getName() + " = " + allHeaders[i].getValue());
        }
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
//            System.out.println(escookie.getName() + " = " + escookie.getValue());
            if (escookie.getName().contains("PHPSESSID")) {
                phpsessioncookie = escookie.getName() + " = " + escookie.getValue();

                //  System.out.println("session cookie : " + sessioncookie);
                //}
            }

//        if (httpresponse.getStatusLine().getStatusCode() == 302) {
//            login = true;
//            System.out.println("localhostr Login Success");
//        } else {
//            System.out.println("localhostr Login failed");
//        }

//        System.out.println(EntityUtils.toString(httpresponse.getEntity()));


            InputStream is = httpresponse.getEntity().getContent();
            is.close();

            System.out.println("php session cookie : " + phpsessioncookie);
        }
    }
 
Example 17
Source File: LoginResult_1.java    From MaterialQQLite with Apache License 2.0 4 votes vote down vote up
public boolean parse(byte[] bytData, List<Cookie> cookies) {
		try {
			if (bytData == null || bytData.length <= 0)
				return false;

			String strData = new String(bytData, "UTF-8");
			System.out.println(strData);
			
			strData = strData.replaceAll("ptuiCB\\(", "");
			strData = strData.replaceAll("\\);", "");
			String[] arrStr = strData.split("',");
			
			if (arrStr.length < 6)
				return false;
			
			for (int i = 0; i < arrStr.length; i++) {
				arrStr[i] = arrStr[i].replaceAll("'", "");
				System.out.println(arrStr[i]);
			}
			
			m_nRetCode = (int)Long.parseLong(arrStr[0]);
			m_strCheckSigUrl = arrStr[2];
			m_strMsg = arrStr[4];
			m_strNickName = arrStr[5];

//			HTTP/1.1 200 OK
//			Date: Tue, 26 Mar 2013 04:08:43 GMT
//			Server: Tencent Login Server/2.0.0
//			P3P: CP="CAO PSA OUR"
//			Set-Cookie: pt2gguin=o0847708268; EXPIRES=Fri, 02-Jan-2020 00:00:00 GMT; PATH=/; DOMAIN=qq.com;
//			Set-Cookie: uin=o0847708268; PATH=/; DOMAIN=qq.com;
//			Set-Cookie: skey=@9Nf6S5Mqa; PATH=/; DOMAIN=qq.com;
//			Set-Cookie: ETK=; PATH=/; DOMAIN=ptlogin2.qq.com;
//			Set-Cookie: ptuserinfo=e5beaee5b098; PATH=/; DOMAIN=ptlogin2.qq.com;
//			Set-Cookie: ptwebqq=b6940e2d89ca07990a9f3edc04c335763a67a97746a573b0afcce74ea46a46e6; PATH=/; DOMAIN=qq.com;
//			Pragma: no-cache
//			Cache-Control: no-cache; must-revalidate
//			Connection: Close
//			Content-Type: application/x-javascript; charset=utf-8
			
			for(Cookie cookie : cookies)
			{
				System.out.println(cookie);
				
				if (cookie.getName().equals("ptwebqq"))
					m_strPtWebQq = cookie.getValue();
				
				if (cookie.getName().equals("skey"))
					m_strSKey = cookie.getValue();
			}
			
			if (m_strPtWebQq != null)
				System.out.println("ptwebqq:" + m_strPtWebQq);
			
			if (m_strSKey != null)
				System.out.println("skey:" + m_strSKey);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
 
Example 18
Source File: OronUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void loginOron() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to oron.com");
        HttpPost httppost = new HttpPost("http://oron.com/login");

//        httppost.setHeader("Referer", "http://www.filesonic.in/");
//        httppost.setHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();

        formparams.add(new BasicNameValuePair("login", "007007dinesh"));
        formparams.add(new BasicNameValuePair("password", ""));
        formparams.add(new BasicNameValuePair("op", "login"));


//        formparams.add(new BasicNameValuePair("remember", "1"));
//        formparams.add(new BasicNameValuePair("username", ""));
//        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);

        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("login")) {
                logincookie = "login=" + escookie.getValue();
                System.out.println(logincookie);
            }
            if (escookie.getName().equalsIgnoreCase("xfss")) {
                xfsscookie = "xfss=" + escookie.getValue();
                System.out.println(xfsscookie);
                login = true;
            }
        }

        if (login) {
            System.out.println("Oron Login successful :)");
        } else {
            System.out.println("Oron Login failed :(");
        }


    }
 
Example 19
Source File: CrockoUploaderPlugin.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void loginCrocko() throws Exception {


        cookies = new StringBuilder();
        HttpParams params = new BasicHttpParams();
        params.setParameter(
                "http.useragent",
                "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        System.out.println("Trying to log in to crocko.com");
        HttpPost httppost = new HttpPost("https://www.crocko.com/accounts/login");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("login", "007007dinesh"));
        formparams.add(new BasicNameValuePair("password", "*********************"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        System.out.println(EntityUtils.toString(httpresponse.getEntity()));
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            cookies.append(escookie.getName()).append("=").append(escookie.getValue()).append(";");
//       
            if (escookie.getName().equals("PHPSESSID")) {
                sessionid = escookie.getValue();
                System.out.println(sessionid);
            }
        }

        if (cookies.toString().contains("logacc")) {
            System.out.println(cookies);
            login = true;
            System.out.println("Crocko login successful :)");
            getData();
        }
        if (!login) {
            System.out.println("Crocko.com Login failed :(");
        }


    }
 
Example 20
Source File: CookieUtil.java    From esigate with Apache License 2.0 4 votes vote down vote up
/**
 * Utility method to transform a Cookie into a Set-Cookie Header.
 * 
 * @param cookie
 *            the {@link Cookie} to format
 * 
 * @return the value of the Set-Cookie header
 */
public static String encodeCookie(Cookie cookie) {
    int maxAge = -1;
    if (cookie.getExpiryDate() != null) {
        maxAge = (int) ((cookie.getExpiryDate().getTime() - System.currentTimeMillis()) / ONE_SECOND);
        // According to Cookie class specification, a negative value
        // would be considered as no value. That is not what we want!
        if (maxAge < 0) {
            maxAge = 0;
        }
    }

    String cookieName = cookie.getName();
    String cookieValue = cookie.getValue();

    StringBuilder buffer = new StringBuilder();

    // Copied from org.apache.http.impl.cookie.BrowserCompatSpec.formatCookies(List<Cookie>)
    if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) {
        buffer.append(BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(null,
                new BasicHeaderElement(cookieName, cookieValue), false).toString());
    } else {
        // Netscape style cookies do not support quoted values
        buffer.append(cookieName);
        buffer.append("=");
        if (cookieValue != null) {
            buffer.append(cookieValue);
        }
    }
    // End copy

    appendAttribute(buffer, "Comment", cookie.getComment());
    appendAttribute(buffer, "Domain", cookie.getDomain());
    appendAttribute(buffer, "Max-Age", maxAge);
    appendAttribute(buffer, "Path", cookie.getPath());
    if (cookie.isSecure()) {
        appendAttribute(buffer, "Secure");
    }
    if (((BasicClientCookie) cookie).containsAttribute(HTTP_ONLY_ATTR)) {
        appendAttribute(buffer, "HttpOnly");
    }
    appendAttribute(buffer, "Version", cookie.getVersion());

    return (buffer.toString());
}