Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.Cookie


    /**
     * Tests if null cookie values are handled correctly.
     */
    public void testNullCookieValueFormatting() {
        Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false);
        cookie.setDomainAttributeSpecified(true);
        cookie.setPathAttributeSpecified(true);

        CookieSpec cookiespec = new CookieSpecBase();
        String s = cookiespec.formatCookie(cookie);
        assertEquals("name=", s);
    }
View Full Code Here


        }
    }

    public void testParseAttributeInvalidCookieExpires() throws Exception {
        CookieSpec cookiespec = new NetscapeDraftSpec();
        Cookie cookie = new Cookie();
        try {
            cookiespec.parseAttribute(new NameValuePair("expires", null), cookie);
            fail("MalformedCookieException must have been thrown");
        } catch (MalformedCookieException expected) {
        }
View Full Code Here

      Calendar calendar = Calendar.getInstance();
      calendar.set(2099, 11, 31);

      client.getState().addCookies(
          new Cookie[] {
              new Cookie(".126.com", "ntes_mail_firstpage",
                  "normal", "/", calendar.getTime(), false),
              new Cookie(".126.com", "logType", "jy", "/",
                  calendar.getTime(), false),
              new Cookie(".126.com", "NETEASE_SSN",
                  getUsername(email), "/",
                  calendar.getTime(), false),
              new Cookie(".126.com", "ntes_mail_noremember",
                  "true", "/", calendar.getTime(), false) });
      String responseStr = doPost(loginUrl, params, "http://www.126.com/");
     
      String redirectUrl1 = getJSRedirectLocation(responseStr);
      redirectUrl1 = redirectUrl1.replaceAll("\\|", "%7C");
View Full Code Here

            calendar.set(2099, 11, 31);
            Cookie[] cookies = client.getState().getCookies();
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals("NTES_SESS")) {
                    client.getState().addCookie(
                            new Cookie(".yeah.net", "NTES_SESS", cookie.getValue(), cookie.getPath(), cookie.getExpiryDate(), cookie.getSecure()));
                }
            }
            client.getState().addCookies(
                    new Cookie[]{
                        new Cookie(".yeah.net", "logType", "9", "/",
                        calendar.getTime(), false),
                        new Cookie(".yeah.net", "ntes_mail_noremember",
                        "true", "/", calendar.getTime(), false)});
            String redirectUrl2 = getJSRedirectLocation(responseStr);
            indexPage = doGet(redirectUrl2, redirectUrl1);
        } catch (Exception e) {
            throw new ContactsException("yeah protocal has changed", e);
View Full Code Here

                new NameValuePair("selType", "jy")};
            Calendar calendar = Calendar.getInstance();
            calendar.set(2099, 11, 31);
            client.getState().addCookies(
                    new Cookie[]{
                        new Cookie(".163.com", "ntes_mail_firstpage",
                        "normal", "/", calendar.getTime(), false),
                        new Cookie(".163.com", "loginType",
                        "js", "/", calendar.getTime(), false)});
            String responseStr = doPost(loginUrl, params,
                    "http://mail.163.com/");

            String redirectUrl = getJSRedirectLocation(responseStr);
View Full Code Here

      NameValuePair params[] = { new NameValuePair("logintype", "uid"),
          new NameValuePair("u", getUsername(email)),
          new NameValuePair("psw", password) };
      client.getState().addCookies(
          new Cookie[] {
              new Cookie("mail.sina.com.cn",
                  "sina_free_mail_recid", "false", "/", null,
                  false),
              new Cookie("mail.sina.com.cn",
                  "sina_vip_mail_recid", "false", "/", null,
                  false) });
      doPost(loginUrl, params, "http://mail.sina.com.cn");
    } catch (Exception e) {
      throw new ContactsException("sina protocol has changed", e);
View Full Code Here

          new NameValuePair("login", email),
          new NameValuePair("passwd", password) };
      content = doPost(loginUrl, params, beforeLoginUrl);

      client.getState().addCookie(
          new Cookie("mail.cn.yahoo.com", "cn_challenge", challenge, "/", null, false));
      String redirectUrl = getJSRedirectLocation(content);
      doGet(redirectUrl);
    } catch (Exception e) {
      throw new ContactsException("Yahoo protocol has changed", e);
    }
View Full Code Here

        Cookie[] cookies = new Cookie[headerElements.length];

        for (int i = 0; i < headerElements.length; i++) {

            HeaderElement headerelement = headerElements[i];
            Cookie cookie = new Cookie(host,
                                       headerelement.getName(),
                                       headerelement.getValue(),
                                       defaultPath,
                                       null,
                                       false);
View Full Code Here

    private static void addInPathOrder(List list, Cookie addCookie)
    {
        int i = 0;

        for(i=0;i<list.size();i++){
            Cookie c = (Cookie)list.get(i);
            if(addCookie.compare(addCookie, c) > 0){
                break;
            }
        }
        list.add(i, addCookie);
View Full Code Here

        log.trace("enter RFC2109Spec.formatCookieHeader(Cookie[])");
        int version = Integer.MAX_VALUE;
        // Pick the lowerest common denominator
        for (int i = 0; i < cookies.length; i++)
        {
            Cookie cookie = cookies[i];
            if (cookie.getVersion() < version)
            {
                version = cookie.getVersion();
            }
        }
        StringBuffer buffer = new StringBuffer();
        buffer.append(formatNameValuePair("$Version", Integer.toString(version), version));
        for (int i = 0; i < cookies.length; i++)
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.