use of cz.msebera.android.httpclient.cookie.Cookie in project AndroidStudy by tinggengyan.
the class HttpCookie method run.
@Override
public void run() {
list.add(new BasicNameValuePair("name", "steve"));
list.add(new BasicNameValuePair("age", "12"));
try {
post.setEntity(new UrlEncodedFormEntity(list));
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
AbstractHttpClient absclient = (AbstractHttpClient) client;
List<Cookie> cookies = absclient.getCookieStore().getCookies();
for (Cookie cookie : cookies) {
System.out.println("name==" + cookie.getName());
System.out.println("value==" + cookie.getValue());
Message message = new Message();
message.obj = cookie;
mHandler.sendMessage(message);
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of cz.msebera.android.httpclient.cookie.Cookie in project android-async-http by loopj.
the class PersistentCookieStore method clearExpired.
@Override
public boolean clearExpired(Date date) {
boolean clearedAny = false;
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
String name = entry.getKey();
Cookie cookie = entry.getValue();
if (cookie.isExpired(date)) {
// Clear cookies from local store
cookies.remove(name);
// Clear cookies from persistent store
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
// We've cleared at least one
clearedAny = true;
}
}
// Update names in persistent store
if (clearedAny) {
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
}
prefsWriter.commit();
return clearedAny;
}
use of cz.msebera.android.httpclient.cookie.Cookie in project android-async-http by loopj.
the class PersistentCookieStore method decodeCookie.
/**
* Returns cookie decoded from cookie string
*
* @param cookieString string of cookie as returned from http request
* @return decoded cookie or null if exception occured
*/
protected Cookie decodeCookie(String cookieString) {
byte[] bytes = hexStringToByteArray(cookieString);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableCookie) objectInputStream.readObject()).getCookie();
} catch (IOException e) {
AsyncHttpClient.log.d(LOG_TAG, "IOException in decodeCookie", e);
} catch (ClassNotFoundException e) {
AsyncHttpClient.log.d(LOG_TAG, "ClassNotFoundException in decodeCookie", e);
}
return cookie;
}
Aggregations