android cookiestore无法删除null cookie

时间:2014-04-08 14:12:41

标签: java android oop cookies

关于Stackoverflow的第一个问题,如果我复制问题或格式错误,我道歉:)

我正在尝试从共享引用重新创建一个cookie存储,当我在日志中打印cookie存储时,总会有一个空cookie。因为它在我使用相同的cookie存储时起作用,我想知道这个空cookie是否导致我的http get给出了无登录响应。如果是这样,我该如何删除它?

public void login(){
    // after login succeed 
    CookieStore store = client.getCookieStore();
    List<Cookie> cookie_list = COOKIES.getCookies();
    //
    Log(1);
    //
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences();
    prefs.edit().putString(COOKIE_SESSION_NAME,cookie_list.get(0).toString()).commit();
}

public void getData(){
    DefaultHttpClient client = new DefaultHttpClient();
    CookieStore store = client.getCookieStore();`enter code here`
    //
    Log(2);
    //
    store.clear();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences();
    String cookieStr =  prefs.getString(COOKIE_SESSION_ID, Configs.INVALID);
    BasicClientCookie cookie =  new BasicClientCookie(COOKIE_SESSION_ID,cookieStr);
    store.addCookie(cookie);
    //
    Log(3);
    //
    client.setCookieStore(store);

    // http get from here

}

这就是日志的样子:

Log(1):
[[version: 0][name: ASP.NET_SessionId][value: 123456][domain: example.com][path: /][expiry: null],
[version: 0][name: .ASPXAUTH][value:123456] [domain: example.com][path: /][expiry: Fri Apr 18 09:36:06 EDT 2014]]

Log(2):
[]

Log(3):
[[version: 0][name: ASP.NET_SessionId][value: 123456][domain: example.com][path: /][expiry: null],
[version: 0][name: .ASPXAUTH][value:123456] [domain: example.com][path: /][expiry: Fri Apr 18 09:36:06 EDT 2014]]
[domain: null][path: null][expiry: null]

0 个答案:

没有答案