2015-11-10 127 views
0

我從Android電子cookie管理器的cookie字符串如何從字符串創建httpcookie?

回報

hl=ru; PHPSESSID=qmvc3c7qq3r07a3dqn7hgk4065 

然後,我用HttpCookie.parse

List<HttpCookie> cookies = HttpCookie.parse(stringCookie); 
      for (HttpCookie c : cookies) { 
      Log.e("My WebView","cookie "+ c.toString()+" | "+c.getComment() + " | " +c.getCommentURL() 
       + " | " +c.getDomain() + " | " +c.getName() + " | " +c.getPath() + " | " +c.getValue()); 
      } 

但是,PHPSESSID總是被丟失,日誌顯示

cookie hl=ru | null | null | null | hl | null | ru 

如何進行適配器轉換?

回答

1

我將初始cookie字符串分開以分開cookie字符串,然後迭代地對它們進行pase。

ArrayList<HttpCookie> cookiesList = new ArrayList<>(); 
String[] singleCookie = cookiesString.split(";"); 
for(String c:singleCookie){ 
    List<HttpCookie> l = HttpCookie.parse(c); 
    cookieList.add(l.get(0)); 
}