Постоянные куки?

Как мне настроить постоянный cookie-файл в определенном URL с помощью Android Studio HttpCookie. Вот мой код:

try {
    CookieManager manager = new CookieManager();
    CookieHandler.setDefault(manager);
    CookieStore cookieJar =  manager.getCookieStore();

    HttpCookie cookie = new HttpCookie(name , value);

    URL url = new URL("http://host.example.com");
    cookieJar.add(url.toURI(), cookie);
    System.out.println("Added cookie using cookie handler");
} catch(Exception e) {
    System.out.println("Unable to set cookie using CookieHandler");
    e.printStackTrace();
}

0 ответов

Другие вопросы по тегам